Adjust the <div> element to dynamically resize based on the user's browser changes

I need a div to adjust its width and height dynamically based on the browser dimensions when a user resizes their browser window.

Implemented code following the provided suggestions:

<!DOCTYPE html>
<html>
    <head>
    <link rel="shortcut icon" href="/favicon.ico"> 
    <meta charset='UTF-8'>
    <%= stylesheet_link_tag 'application' %>
    <title>Some Company - Terms and Conditions</title>
</head>
<body >
<div>
    Links to content within the div below can go here.
    </div>
   <div style="position: absolute; top: 100; bottom: 0; left: 0; right: 0;overflow:auto;padding:10px;border:1px solid lightblue;">
     Content goes here
    </div>
</body>

The final outcome looked like this:

<!DOCTYPE html>
<html>
<head><title>Terms and Conditions</title></head>
<body>
<a href="#tac20">Terms and Conditions 20</a> | <a href="#tac40">Terms and Conditions 40</a>

    <div style="position:absolute; top: 30px; bottom: 0; left: 0; right: 0;overflow-y:auto;padding:5px;border-top:1px solid lightblue;">
        Terms and Condition 1 <br/>     
        Terms and Condition 2 <br/>
        Terms and Condition 3 <br/>
        Terms and Condition 4 <br/>
        Terms and Condition 5 <br/>
        Terms and Condition 6 <br/>
        Terms and Condition 7 <br/>
        Terms and Condition 8 <br/>
        Terms and Condition 9 <br/>
        Terms and Condition 10 <br/>
        Terms and Condition 11 <br/>        
        Terms and Condition 12 <br/>
        Terms and Condition 13 <br/>
        Terms and Condition 14 <br/>
        Terms and Condition 15 <br/>
        Terms and Condition 16 <br/>
        Terms and Condition 17 <br/>
        Terms and Condition 18 <br/>
        Terms and Condition 19 <br/>
        <a name="tac20">Terms and Condition 20</name> <br/>
        Terms and Condition 21 <br/>        
        Terms and Condition 22 <br/>
        Terms and Condition 23 <br/>
        Terms and Condition 24 <br/>
        Terms and Condition 25 <br/>
        Terms and Condition 26 <br/>
        Terms and Condition 27 <br/>
        Terms and Condition 28 <br/>
        Terms and Condition 29 <br/>
        Terms and Condition 30 <br/>
        Terms and Condition 31 <br/>        
        Terms and Condition 32 <br/>
        Terms and Condition 33 <br/>
        Terms and Condition 34 <br/>
        Terms and Condition 35 <br/>
        Terms and Condition 36 <br/>
        Terms and Condition 37 <br/>
        Terms and Condition 38 <br/>
        Terms and Condition 39 <br/>
        <a name="tac40">Terms and Condition 40</name> <br/>
    </div>
</body>

Answer №1

Finding the perfect solution really comes down to how your webpage is set up. When dealing with a single div that you want to stretch across the entire browser window, I personally prefer using this CSS code:

#mainDiv { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }

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

How to customize the checkbox color in Material UI?

I've been attempting to adjust the color of checkboxes and radio buttons. After conducting some research, I stumbled upon this helpful link: Material UI change Input's active color Unfortunately, I keep encountering the following error: (0 , _ ...

"Learn the process of connecting an HTML5 element to Angular 2 source code while in a saving mode

In this Angular2 implementation, I have created some HTML code for user access. However, I am facing an issue where the data is not binding at the Angular2 source code side. HTML Code <form class="form-horizontal" novalidate [formGroup]="EmployeeForm" ...

Place elements at the bottom of a webpage on any browser or device with just a single page

I am in the process of creating a website that features a top menu and a background image with text on the home page, covering the full screen. However, I also need to include 3 blocks at the bottom of the screen that should display consistently across all ...

Whenever I include "border:0" in the styling of my hr element, a significant number of hr elements fail to appear on the screen

I have been experimenting with using hr elements to divide sections of my web page. Here is a snippet of the CSS code I am using: hr{ content: " "; display: block; height: .1px; width: 95%; margin:15px; background-color: #dfdfdf; ...

"Term" symbols from the Unicode Range

I have been curious about how PCRE detects word characters from any language. In my testing, I used this string: "間違つ" The PHP file is UTF-8 encoded and properly tagged with Charset=UTF-8 in the Content type tag. <?php $string="&b ...

Developing an object that displays animated effects when modifying its properties, such as visibility, and more

Exploring the realm of animations in JavaScript and AngularJS has led me to the idea of creating a unique JavaScript object. Imagine having the ability to define an object where setting an attribute like obj.visible = true Would automatically make the ...

Issues with Vue.js v-for functionality causing inconsistencies

Just delving into the world of Vue.js and encountering a hitch. I've been following a tutorial on Laracasts, but my v-for directive seems to be causing some trouble. Here's the HTML: <div id="root"> <ul> <li v-for="name in ...

JavaScript pause until the DOM has been modified

My current situation involves using a JavaScript file to make changes to the DOM of a page by adding a navigation menu. Following this code, there is another function that further modifies the newly added navigation menu. However, I am facing an issue wher ...

Boxes not occupying entire vertical space

My structure is unique, like a 9-box with div elements: <div class="NBWrapper"> <div class="NBTopRow"> <div class="NBLeft" /> <div class="NBRight" /> <div class="NBMiddle" /> </div> & ...

Values do not appear as expected post PDF conversion using wkhtmltopdf

Currently, I am updating certain values within my HTML page by following this process: The function: function modifyContent(){ var newTitle = document.getElementById('myTextField1').value; if( newTitle.length==0 ){ alert('Plea ...

Setting the background color in the navbar of a Laravel application

I'm having trouble changing the color of my navbar to blue in certain parts. I've tried using background: lightblue;, but for some reason, two sections remain white. How can I make them completely blue? (see screenshot below) Any help would be ap ...

Ways to display or conceal various divs by employing an if/else statement?

I am aiming to conditionally display various divs based on certain criteria: Show the "x" div if it's not already visible Display the "y" div only if the "x" div is already being displayed Show the "z" div only if both the "x" and "y" divs are alrea ...

The button's background color remains the same even after clicking on it

In my exploration of Vue.js, I decided to create a simple project to grasp the concept of class binding. I wanted to add functionality to each button component, so that when a button is clicked, it would change its color or background color to something ot ...

Choose a specific <div> element from an external page using Ajax/PHP

I'm encountering a small issue. I am currently utilizing Ajax to dynamically load content from another page into a <div> element after detecting a change in a <select>. However, my specific requirement is to only load a particular <div& ...

Need a guide to identify HTML elements with a particular attribute?

I attempted to find this information online, but I wasn't successful. Suppose I am interested in knowing all the HTML elements that contain a "background" attribute. I'm aware that some web browsers may not support certain elements. Off the top ...

What is the best way to assign names to images in a Rails application?

When working in html, you can use the code <img class="myimage" src="image.jpg"> to make editing in .css simpler. But what is the equivalent of this when dealing with a .html.erb file? For example, where should I define the class in this <%= imag ...

Is it possible to employ a dynamic size in media queries based on width?

Delving into the world of media queries as a novice, I stumbled upon an interesting condition while developing a Desktop application using electron. Although the CSS concept remains consistent with normal web development, a new challenge presented itself. ...

Having trouble with implementing a static URL in CSS

I'm struggling to incorporate a static file into my CSS as a background image for my website. The static URL is functioning properly when tested in HTML, but it's not working when implemented in CSS. HTML: {% extends 'base.html' %} { ...

Tips for creating a clickable title that directs to a URL

I am currently using the "Import All" WordPress plugin to bring in an Excel file containing numerous hyperlinks that point to specific Custom Post Types and a designated field. These hyperlinks are separated by commas from the corresponding title. For exam ...

Implement a maximum height restriction on the children of the Select component in Material-UI

Currently, I am working with the Material-UI react library to create Dropdown menus by utilizing components like <FormControl>, <Select>, and <MenuItem>. The options array for these dropdown menus is quite extensive, and I am looking to s ...