Creating a layout in CSS and HTML that spans 100% of the width

My goal is to create a layout that fills the entire visible space in the browser. I followed suggestions from various Stack Overflow posts by setting html, body height 100%. Below is the markup I am currently using:

<div>
  <div class="header">
  </div>
  <div class="main">
    <div class="container">
        <div class="content"></div>
    </div>
  </div>
</div>

CSS:

html, body {
  height: 100%;
  max-height: 100%;
}
.header {
  height: 30px;
  background-color: #000;
}
.main {
  height: auto;
  padding-right: 0px;
  max-height: 100%;
  width: 100%;
  display: block;
  clear: both;
  background-color: #eee;
}

.container {
  width: 90%;
  overflow-y: scroll; 
  background-color: #ccc;
}
.content {    
  height: 2000px;
  width: 80%;
  background-color: #fff;
}

The height of the content div causes the entire body to expand, resulting in the default browser scroll bars being displayed. Although I set the container div to scroll for the purpose of showing the content within the content div, the scroll bars for the container div are not appearing. How can I resolve this issue?

Here is the jsfiddle

Answer №1

Updated Content:

The height of a div element is typically dependent on its content, unlike the width which automatically takes up 100% of the parent container. This can lead to discrepancies when specifying the height of an inner element as a percentage if the parent container does not have a defined height (as height is not inherited).

In this scenario, it is necessary to add a specific height value, such as height: 100%;, to the .container, .main, and wrapper div.

View modified fiddle here

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 activate the menu in AngularJS

Within my application, I have a header that contains various menu items. These menu items are fetched from a service and displayed in the header. When hovering over the main list, the submenus appear. My goal is to highlight the parent item as active when ...

Updating image attributes using jQuery within an .each loop

My challenge involves a textarea where I paste HTML code, followed by a button that should display all the images from that code along with their respective alt text and titles. The goal is to easily update the alt text and titles for each image individual ...

Is there a way to compel Blazor to display a lone, non-breaking space?

Blazor has a default behavior of trimming "insignificant" whitespace during compile time, as mentioned in this Microsoft document. Moreover, Blazor also trims significant whitespace. For instance: <span>some text</span> @if (true) { <sp ...

The website is unresponsive to the media query

Currently, I am working on a project using Windows 10, Codeigniter, jQuery, and Firefox 43.0.4. However, I am facing an issue that is quite baffling to me. My goal is to apply styles specifically for an iPad-sized window, so I have implemented the followin ...

Interaction between index file and module instance

As I develop a computer system, I have divided it into various smaller components. My experience in software development has taught me the value of keeping systems compact and focused. To achieve this, I am creating modules that perform specific function ...

What is the best way to eliminate the left margin entirely in CSS?

I am attempting to create an image view that fully covers the window, without any margins. I have tried various solutions such as setting the body margin and padding to 0, but they do not seem to work. body { margin: 0px; padding: 0px; } or *, html { ...

Storing the entire HTML5 game on the local device for faster loading and

I'm in the process of developing a 2D HTML5 game and I'm looking to optimize asset storage by requesting each asset only once and then storing them in the user's filesystem. Currently, I'm utilizing localStorage for this purpose, but it ...

What is the best way to adjust the size of the circles in my d3 leaflet implementation based on the frequency of longitude/latitude pairs?

I'm currently diving into the world of d3 and attempting to create a map using leaflet. Within my dataset, I have thousands of latitude and longitude coordinates. While I've successfully plotted circles on a leaflet map in d3, I'm now faced ...

Guide to importing a JSON file into Vue.js and HTML

I'm a beginner in Vue and not very familiar with HTML I'm attempting to import data from a JSON file into my interface to display it for the user. Below is the structure of the JSON: [ { "Title": "SOFT-STARTER", "Cod&q ...

Leverage nearby data using MediaSource

I am currently working on creating a local video player using nwjs (node-webkit). I have successfully played local files by setting their path as the src attribute of the video element. Now, I want to explore using MediaSource and potentially URL.createObj ...

What could be causing my ajax request to not be successfully compiled?

I seem to be experiencing an issue with this part of my code. Despite trying multiple methods, it still isn't functioning correctly. What steps can I take to resolve this problem? $.ajax({ url: "https://corona-api.com/countries/BR", ...

Elements not being styled by CSS properties

I am facing an issue with a CSS file designed to theme a page in white on black, as opposed to the usual black on white. body { background-color: black; } h1 h2 h3 h4 h5 h6 p { color: white; } However, the color: white; property is not being applied ...

Adjust the horizontal position of a span element from left to right based on its class

Welcome to my first question here, with many more to come in the future. I have an issue with positioning that I'm not sure is possible to solve. The problem arises with an unordered list (<ul>) containing floated <li> elements. For the m ...

Using attribute value for CSS background-image styling is a handy technique to

In my current situation, the design calls for the use of two different images as background images - one for desktop and another for mobile. These images are uploaded through a CMS, allowing me to retrieve the URLs for both using PHP. Is there a way to pa ...

The webpage is not updating when the src value of the iframe is changed

Utilizing an IFrame on my main page to load various pages has been somewhat problematic. Occasionally, the first 2-3 pages load correctly when I set the source by clicking a link with the following JavaScript: var frame = $('#mainFrame')[0]; fra ...

Navigating sidebars with jQuery Dropdowns

Currently, I am working on creating a slide-in and out navigation menu that displays icons when minimized. Upon hovering over the icons, the menu expands to reveal links. However, I am encountering an issue where I cannot get a dropdown to display when hov ...

Excessive screen height causes the CSS box layout to overflow

I am looking to create a screen layout similar to the one shown in this image. It should consist of a row with no overflow and include: A left box that contains: A fixed height header (20px), An aspect square box taking up the remaining height. ...

Setting the maximum height for a div element

Struggling to understand how a div can occupy the entire height of a container. In this particular scenario, I am aiming for the "photo" div to take up the full height, with the yellow and green content appearing on the right side of the photo. Below is th ...

"Google Maps Integration: Customize Your Map with Grey Color Scheme and User-F

After reviewing the other questions and answers related to my problem, none of them seemed to address it. The issue is that when loading and placing a marker, the map seems to "freeze," turns grey, but still displays controls. The marker ends up in the up ...

JQuery's animations and their influence on element positioning

My thumbnail animation increases in size on hover, but it is affecting the position of the other images. The issue is that when hovering over an image, the others move down and to the right to make space for the animated one. I want the other images to st ...