Completely adhering to standards and employing a semantic method for creating sections that utilize the

My goal is to create sections with a minimum height of 100%, and it seems like the general recommendation is:

html{
  height: 100%;
}
body {
  min-height: 100%;
}

Even direct children should have a min-height of 100%. The confusion arises when HTML has a fixed height of 100% while the body can expand, resulting in a potentially disjointed document structure. This scenario raises concerns about semantics, such as the relationship between html and body tags. Furthermore, if your section is nested within multiple other divs, all parent elements may also need a min-height of 100%. This approach appears somewhat unconventional.

What would be the most elegant solution? While height: 100vh is ideal, browser support varies. Would using JavaScript to determine the viewport size and set the height property for relevant sections be a better alternative?

Answer №1

The concept of the "unconventional" issue is very valid and not as out-of-the-box as it may seem. In reality, browsers only take into account the horizontal layout by default, neglecting the vertical unless specifically defined. This means that if you want an element to have a height of 100%, you must first define the height explicitly for all of its ancestor elements so that the browser can accurately calculate the dimensions.

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

What's the best method for styling a textarea in HTML without affecting the positioning of other elements?

I'm relatively new to HTML and I'm working on a platform using Apps Script. This platform is designed to analyze specific attributes of users, which are accessed through a window containing all the relevant information about that user. The data i ...

Does the flex-grow property depend on the flex-basis in flexbox?

Check out this snippet of HTML code <div class="container"> <div class="box box1">one ...

Which is better for website footers: tables or nested ULs?

I am trying to create a footer with a specific layout that consists of item titles and images. The design I have in mind includes three columns, where the middle one is larger than the sides. The middle column should be 550px wide, while the side columns s ...

Building a stable sidebar design using Bootstrap 4 - A step-by-step guide

https://i.sstatic.net/QLeA4.png Struggling to replicate a layout similar to the provided screenshot using Bootstrap 4. The issue arises when trying to make the sidebar fixed while maintaining the desired layout. To illustrate with a basic example: <d ...

Incorporate additional attributes within ASP.NET's HTML Helpers for enhanced labeling functionality

Is it achievable to create the following label tag using HTML Helpers? <label class="myClass" attr1="attr1Value" attr2="attr2Value" attr3="attr3Value">labelText</label> This is essentially a regular label tag with 3 additional attributes. ...

Increase the size of clickable hyperlinks in CSS

I am looking to increase the clickable area of my menu links. Currently, only a small part of the links is clickable and I want to know how to expand it. I have seen some CSS tricks using classes, but I also have an active class for these links. Can you ...

The sticky table header is being covered by a disabled HTML button, while the active buttons are not visible

I'm currently working on a website using Bootstrap 5 as my framework. The issue I'm facing is that when scrolling down the page and keeping the table header stuck to the top, the disabled button ends up showing over the header. I attempted to us ...

How can you identify English words along with non-English characters and special characters using JavaScript regex?

Dealing with a text that consists of English and Chinese characters can be tricky. I need to separate out the English words, foreign characters like French or Chinese, numbers, and special characters such as "@#$%^&>?", so that I can manipulate them ...

Having issues with jQuery Checkbox Selector and .attr('checked) function not functioning correctly?

I'm trying to assign the value of a variable as true or false based on the selected checkbox. However, the code I have is not working as expected. <input type="checkbox" id="chkBox1"> var chkBox1Val = $('#chkBox1').prop('checked ...

Is there a way to easily align the text of the links in the bootstrap navbar to the center when it collapses?

I'm having trouble centering the links in the dropdown menu. Here is the code snippet: <nav class="navbar navbar navbar-expand-lg fixed-top bg clean-navbar"> <div class="container logo" style="position: relative;"> <a clas ...

arranging <li> elements in alphabetical order

I'm looking for a way to alphabetically sort an unordered list while still keeping the outer html intact. My current method sorts the list alphabetically, but it only reorganizes the inner html of the list elements and not the entire element itself. T ...

The :not() selector in CSS3 seems to be ineffective on sibling elements

In my simple design, I have specified that text should appear in red unless it is within a footer element. This style is applied successfully to p tags, a tags, and others. However, for some reason, the styling does not work when I target the footer tag. ...

Center the form on the page using Bootstrap

My bootstrap login form is currently appearing at the top of the page, but I want it to be centered. <div class="container"> <div class="row text-center"> <div class="col-sm-6 col-sm-offset-3 well offset4"> <div class=""&g ...

Retrieve selected value from HTML input with datalist and use it as an argument in a method

I have a datalist in my HTML input where I need to pass the selected value into JavaScript / Angular. It must be passed because the datalist is being used in an HTML table with multiple entries. Most examples I've come across show how to grab the valu ...

What is the best method to make an email address distinct?

<body> <p>Please input your email address:</p> <input id="email" style="margin-bottom: 20px; margin-top: 2px;" type="email" placeholder="Email Address"> <input onclick= "validateEmail(email)" type="su ...

Positioning a div with a set size to the right while allowing a div with a variable width to the left

Even though I achieved the desired outcome in this example (http://jsfiddle.net/jcx3X/40/), I am intrigued by the reasons why this other scenario (http://jsfiddle.net/jcx3X/41/) does not work. What is the significance of the div being floated first in th ...

Troubleshooting flow problems in flexbox container for

https://i.stack.imgur.com/ZpVaH.png I have implemented a flexbox-based page layout. The layout consists of two sidebars on the left and right sides, with fixed widths, and a central content panel that dynamically adjusts to fill the remaining space. Howe ...

Using flexbox to evenly distribute images with borders and padding to ensure consistent height

Currently, I am utilizing jQuery to adjust the flex-grow value of a wrapper div based on the aspect ratio of a figure's image. This approach was suggested here. However, once I apply a border and padding to the figure, the images no longer retain the ...

Unexpected behavior with overflow:scroll in the <body> tag

Take a look at this image and code snippet: <!doctype html> <html> <head> <style> body { border: 1px solid red; padding: 20px; overflow: scroll; ...

Upload an image to a Laravel controller using AJAX

I am currently attempting to use AJAX to send a form with an image (file) to a Laravel backend. So far, I have been trying to make it work using form data, but I am only able to retrieve the parameters and not the file. For now, I am simply logging the co ...