Creating a straightforward CSS design that stretches to fit the entire viewport dimension

I am attempting to create a simplistic layout using HTML/CSS, as depicted in the wireframe below:

/------------------------------------------\
|                                          |
|                header div                |
|                                          |
|------------------------------------------|
|                                       |S |
|                 main div              |C |
|                                       |R |
|                                       |O |
|                                       |L |
|                                       |L |
|                                       |  |
|                                       |B |
|                                       |A |
|                                       |R |
\------------------------------------------/

The design consists of a 200 pixel high "header" DIV that spans the full width of the viewport horizontally. Below it, there is the "main" DIV intended to occupy all remaining empty space both horizontally and vertically. The scrolling feature is set to "auto" in case of content overflow.

The challenge lies in making sure the "main" DIV fills the rest of the available space without the use of JavaScript. I have found difficulties with percentage heights while ensuring the visibility of the scrollbar.

At this stage, I am open to considering tables for this basic layout element if no non-JavaScript solution exists. Semantic structure is not a priority in this case.

How should I proceed with implementing this? An example demonstration would be greatly appreciated!

Answer №1

After experimenting with various options, I have discovered that using percentages for the height and setting a minimum height for the header to 200px is the closest pure-css solution available. However, there is a slight issue when the viewport size is smaller than expected, causing the bottom div to go beyond the fold.

To resolve this issue, it would be beneficial to analyze your visitor statistics and determine the most common screen height used, which is typically around 800px. Based on this information, you can set the following:

#head {
      height: 25% (adjust as needed)
      min-height: 200px;
}
#body {
      height: 75%;
}

By implementing these adjustments, your design will function optimally in most scenarios.

However, the rationale behind ensuring all content remains above the fold in today's digital landscape seems unnecessary. With scrolling becoming second nature to users and the prevalence of widescreen designs, it is more practical to embrace scrolling as a natural behavior.

Answer №2

In my opinion, the only way to achieve that specific behavior without using javascript is to set static heights. When data doesn't exceed a certain height limit, scrollbars won't appear. Using an iframe might be an option, but I wouldn't recommend it due to increased loading time.

Answer №3

CSS property: display - table or

Answer №4

For those in need of a reliable layout, I recommend exploring this tried-and-true design:

It showcases the process beautifully.

Answer №5

I recently completed a project that involved similar tasks for a client, but unfortunately I'm unable to share the specifics at this time. However, I can provide some guidance on using margins in your CSS code:

#header{
  margin-top: 0;
  margin-left: 0;
  margin-right: 0;
  height: 200px;
}

#content{
  margin: 200px 0 0 0;
  top: 200px; 
}

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

PHP allows for creating dropdown lists where the values are dynamically dependent on the selection of another dropdown list within the same form

Is there a way for me to implement this solution? The values in the dropdownlist are based on another dropdownlist within the same form. For example, a form with dropdownlists for car names and models of that car, along with a search button. Please take no ...

Enhance iframe with hover effect

I'm currently working on a unique WordPress blog design where images and iframes (YouTube) transition from monotone to color upon hover. So far, I've successfully implemented the grayscale effect for images: img { -webkit-filter: grayscale(100% ...

Adjusting jQuery inputmask mask according to dropdown selection: A complete guide

I am utilizing jQuery inputmask to achieve a specific effect: Currently, I have set up a simple formatting for US & Canada phone numbers like this: $("#user_phone").inputmask("mask", { "mask": "(999) 999-9999" }); However, I want to dynamically chan ...

Maintain the aspect ratio of an image when placing it in a square container

Looking for a way to create a CSS grid with non-square random sized images? I need help filling all the space inside a fixed size div. Any suggestions? Check out my example: (blue represents the fixed size div and red shows the image inside it) ...

Display an AJAX div when the image is hovered over and have it track the movement of

I am seeking assistance with my website project, which involves providing users with download links to movies. However, I am struggling to make the preview_block div(id) appear when the mouse hovers over the movie_block div(id). Additionally, I am having ...

"Why does the font on my website look different on my computer before I upload it to my web host? How can I fix

I am currently developing a website and have chosen the font "PT Sans Narrow" for it. Unfortunately, it seems that Chrome and many other browsers do not support this font by default. Is there a way to include the PT Sans Narrow font with the website when ...

CSS hover effect not working while mouse is in motion

As a beginner in HTML, CSS, jQuery, and JavaScript, I've been trying to trigger a div when hovering over one area using the adjacent siblings code. However, I'm encountering an issue where if I move my mouse after triggering the event, it keeps r ...

What is the best way to include a JavaScript variable in an HTML image src tag?

Even though I know the answer to this question is out there somewhere, I just can't seem to find it (or maybe I'm not recognizing it when I see it!). As a beginner in jquery, please be patient with me. Dilemma: I have a collection of 20 images, ...

Adjustable background image with no need for a scroll bar

I am looking to create a static webpage that remains fullscreen without any scrolling. My goal is to have a centered form with the background image adjusting to the window size. As a beginner, I apologize if this request seems too simple. .container { ...

After checking the checkbox to add a class, I then need to remove that class without having to interact with the entire document

When I click on a checkbox, an animation is added to a div. However, I am struggling to remove this animation unless I click elsewhere on the document. The goal is for the checkbox to both add and remove the class. JS $('#inOrder').click(functi ...

How to implement Bootstrap 5 Floating Label in Contact Form 7 for maximum impact?

I'm having trouble with the new form feature, specifically Floating labels (Bootstrap 5) in Contact Form 7 on Wordpress. The issue arises when a <p> tag is added inside the <input> tag. It seems to break the functionality, but I'm not ...

"Implement a smooth transition effect lasting 1000 milliseconds when a class is added via

I'm attempting to use the fadeIn 1000 effect when a class is added through a Click function. I have already attempted this: http://jsfiddle.net/rf7mudL5/ HTML <span class="date-outer">Text will Red on fadeIn</span> <button class="mo ...

Is there a way to conceal a component using Twitter Bootstrap while having the ability to reveal it with the help of

Suppose I generate an HTML element in the following manner, <div id="unique-div" class="concealed">Hello, TB3</div> <div id="unique-div" class="hide-me">Greetings, TB4</div> <div id="u ...

Navigating a series of HTTP requests with VBA and saving the retrieved data in Excel 2010

I have a total of 5 Excel files that I currently use with WinHttpRequest to extract data into them. My goal is to consolidate all the requests into a single VBA script, loop through them, and store the data sequentially on one sheet. However, I am facing ...

Display the homepage if a user accesses a page intended for an ajax request

Currently, I am utilizing jQuery to create a straightforward website. The main page is called 'index.html' and it has the capability to load different content (such as 'info1.html' or 'info2.html') through jQuery ajax requests ...

Injecting a component in Angular 2 using an HTML selector

When I tried to access a component created using a selector within some HTML, I misunderstood the hierarchical provider creation process. I thought providers would look for an existing instance and provide that when injected into another component. In my ...

JavaScript functions do not work within the HTML code

I am currently working on my debut website and I'm facing an issue with the JavaScript file not functioning properly. Is there a chance you can help me troubleshoot this? I'm still in the learning stages of programming. This is the HTML content ...

What is the best way to include multiple <p> elements in a row using Bootstrap?

What is the best way to display multiple <p> elements inline using Bootstrap? This is the code I have currently: <div className="container d-inline-flex"> <p className="text-nowrap"> This is sent ...

Challenges of aligning a modal overlay in the middle of mobile screens

Currently, I am developing a website and encountering a specific issue with the modal structure. When viewing it on Codepen using Chrome devtools and toggling the device toolbar to simulate mobile screens, everything appears fine. However, when opening the ...

Table featuring alternating background colors for rows and a distinct header design

Incorporating CSS, I have managed to style my rows in alternating colors. Take a look at the code snippet below: Fiddle tr:nth-child(odd) td { background-color:red; } tr:nth-child(even) td { background-color:blue; } tr th { background-color: yellow} ...