Is it possible to make a DIV adjust its size automatically when the browser is resized?

Greetings! Here's my initial query, with more to follow.

I've encountered an issue where a div on my page is set to 70% of the screen, but upon resizing the browser to a smaller size, some content within the div extends past the bottom of the page. It's quite difficult to articulate.

The scrollbar also extends below the page.

Sharing the CSS for the troublesome div below:

#header {
position: fixed;
width:100%;
height:100%;
z-index: 90;
overflow:auto;
}

#navigation {
margin-top:20px;
display:block;
list-style:none;
z-index:3;
margin-bottom:10px;
}

#navigation a{  
margin-top:0;
color: #444;
display: block;
background: #fff;
background: rgba(255,255,255,0.9);
line-height: 50px;
padding: 0px 10px;
text-transform: uppercase;
margin-bottom: 6px;
box-shadow: 1px 1px 2px rgba(0,0,0,0.2);
font-family: 'Cinzel', serif;
font-weight:600;
font-size: 19px;
text-align:center;
}

.panel{ 
overflow:auto;
right: 40px;
left: 40px;
height:70%;
position: fixed;
margin-top: -150%;
margin-bottom:auto;
background-color: #008aff;
opacity: 0;
z-index:2;
-webkit-transition: opacity .6s ease-in-out;
-moz-transition: opacity .6s ease-in-out;
-o-transition: opacity .6s ease-in-out;
-ms-transition: opacity .6s ease-in-out;
transition: opacity .6s ease-in-out;

Here's a glimpse at the corresponding HTML:

<div id="header>
            <div id="navigation">
                <table align="center">
                    <tr>
                        <th width="300px" align="center">
                            <img src="logo.png" height="165px">
                        </th>

                        <th width="140px" align="center"><a id="link-home" href="#home">Home</a></th>
                        <th width="140px" align="center"><a id="link-portfolio" href="#portfolio">Portfolio</a></th>
                        <th width="140px" align="center"><a id="link-services" href="#services">Services</a></th>
                        <th width="140px" align="center"><a id="link-about" href="#about">About</a></th>
                        <th width="140px" align="center"><a id="link-contact" href="#contact">Contact</a></th>
                    </tr>                        
                </table>
            </div>
            <div class="main">

                    <div id="home" class="panel">
                        <h2>Home</h2>
                        <p></p>
                </div>

                <div id="portfolio" class="panel">
                        <h2>Portfolio</h2>
                        <p>What I&rsquo;ve Done</p>
                </div>

                <div id="services" class="panel">
                        <h2>Services</h2>
                        <p>
                            - Line 1<br>
                            - Line 2<br>
                            - Line 3<br>
                            - Line 4<br>
                            - Line 5<br>
                            - Line 6<br>
                            - Line 7<br>
                            - Line 8<br>
                            - Line 9<br>
                            - Line 10<br>
                            - Line 11<br>
                            - Line 12<br>
                            - Line 13<br>
                            - Line 14<br>
                            - Line 15<br>
                            - Line 16<br>
                            - Line 17<br>
                            - Line 18<br>
                            - Line 19<br>
                            - Line 20<br>

                        </p>
                </div>

                <div id="about" class="panel">
                        <h2>About Brem Media</h2>
                        <p>
                            Been in the Game a while!
                        </p>
                </div>

                <div id="contact" class="panel">
                        <h2>Contact</h2>
                        <p>
                            Phone: 519.991.3671<br>
                            E-Mail: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a1c8cfc7cee1c3d3c4ccccc4c5c8c08fc2cecc">[email protected]</a>
                        </p>
                </div>

            </div>
        </div>

Answer №1

Hi there! I hope everything is going well for you. I decided to test out your setup on my own system, and I noticed a few issues that needed to be addressed. Firstly, the content was not displaying properly due to:

  1. The opacity being set to 0 (making it invisible)
  2. The margin-top being set to -150% (as mentioned in the comments)

To resolve this, I removed these CSS values to reveal the hidden div. Surprisingly, the scaling was perfect once these changes were made. I believe you may have intended to show something like this:

Check out how it looks on my browser

Here is a screenshot of your code running on Vivaldi (a Chromium-based browser).

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The window.load() function seems to be malfunctioning as the event is not being triggered. There are no error

I'm struggling with getting the window.load() event to trigger on this specific website. The issue arose last night and despite there being no visible js or php errors, pinpointing the root cause has proven to be quite challenging. In syrp.home.main ...

Changing navigation position while scrolling to a different anchor using fullpage.js

Currently, I have a lengthy scrolling webpage that utilizes fullpage.js. The navigation is fixed in position over the page and each active slide is highlighted by its corresponding link. My goal is to have the link move to the top position when it's ...

Look through the contents of each child within a div to locate specific text, then conceal any that do not include it

I want to dynamically hide divs that do not contain the text I specify. Here is the code I have tried: var $searchBox = $('#search-weeazer'); $searchBox.on('input', function() { var scope = this; var $userDivs = $('.infor ...

If the width is divisible by a certain value

I have a question regarding the width of my element that I want to divide by 90. If this width is a multiple of 90, I set the width of the element. If not, I move on to the next. For example, when the window width is 1000px and the element is at full widt ...

What do you think about removing the Bootstrap styling from the design?

As a newcomer to Bootstrap and currently working on my second project using this framework, I find myself struggling with overriding CSS styles. It can be time-consuming to locate the specific style that needs to be changed rather than starting from scratc ...

Troubleshooting Problems with CSS in Safari (Could Negative Margins be the

My problem lies specifically in Safari. Here is a screenshot of the issue: https://i.sstatic.net/amPeA.png To further investigate and experiment, I have created a fiddle at https://jsfiddle.net/hbadvb02/6/. Interestingly, the code works perfectly in Ed ...

Having trouble with a basic select tag and options not functioning properly in Chrome browser

I encountered an issue where I am unable to expand a simple select tag in Chrome. <select id="filterCategory" class=""> <option>1</option> <option>2</option> <option>3</option> <option>4</option ...

Tips for Establishing Communication Between Two Dynamic Canvas Elements

How do I establish communication between two animated canvas elements? I have created two HTML5 canvas animations using Adobe Animate CC. Both of these animations are placed on a single HTML page. I am able to call functions from within the animations and ...

Extract particular details from my database

I need help creating a table to display all chat messages sent to the server. I have the table set up, but now I want to make it so that when I click on a user's name like 'demo', it will show me all the chat messages sent by that specific u ...

Does the body element inherit the line height property?

Below is some simple HTML code consisting of a div and a span: <div id="container">Some text to affect the width</div> <span>A</span> I am currently using Eric Meyer's CSS Reset, which sets the line-height of the body to 1 an ...

What is the best way to narrow down the content cards displayed on the page?

I have recently developed a blog post featuring three distinct categories: digital marketing, tips and advice, and cryptocurrency. My goal is to implement a filtering system for these categories. For instance, I would like users to be able to click on a b ...

Python is experiencing difficulties with copying xpath elements

I attempted to utilize some Python code to access Twitter and retrieve the "Happening now" text. Unfortunately, it was unsuccessful. import webbrowser print("Visiting Twitter.com...") webbrowser.get('C:/Program Files (x86)/Google/Chrome/Application/c ...

Converting an NPM package into a gulp workflow

I'm currently generating html files from Nunjucks using my gulp file. Now, I need to convert these html files into text files. I came across a useful NPM package called html-to-text that can help with this task. However, I'm facing some challenge ...

The cube mesh is failing to render inside the designated div

I created a Torus and Cube Mesh in my scene, but I want the cube to be positioned at the bottom right corner of the screen. Here's what I tried: <div style="position: absolute; bottom: 0px; right:0px; width: 100px; text-align: center; "> & ...

Conducting various calculations and showcasing them all on a single webpage

Uncertain about what to name this, but let's see if you understand my question. I have a table on a standard HTML page and I am performing some calculations using Javascript/jQuery. Example: function addThem() { var result; result = userIn ...

Is there a way to identify the source of a div's scrolling behavior?

While working on a complex web page that involves multiple JQuery Dialogs and other widgets, I encountered a frustrating issue. Some of the dialogs contain divs with scrolling abilities (using overflow-y with a fixed height). Whenever I click on one dialog ...

Having issues with Drupal's lightframe and lightbox functionalities not functioning properly

I recently came across a Drupal 6 project that I have little knowledge about. My goal is to incorporate an Iframe into a lightbox, which seems simple but I'm encountering some obstacles. Despite researching online and attempting to implement the code ...

How can I ensure a div expands over another element when hovering the mouse?

I have a development div in the footer with a hover effect that expands it. However, it is currently growing underneath the top element on the site. I want it to expand on top or push the element above. Website: I've tried using position, float, and ...

Adjust the size of multiple elements upon hovering over one of them

I encountered a puzzling issue, and here is a demonstration of my problem: https://jsfiddle.net/k1y8afst/ <div class="Sample"> <div class="Dummy"> <div class="Books"> <a st ...

Convert HTML content to a PDF file with Java

Welcome to the community! My project involves extracting data from a website containing information on various chemical substances and converting it into a PDF while preserving the original HTML formatting, including CSS styles. For example, here is a li ...