What causes a div element to not be 100% width when all its predecessors are already set to 100

Why are the divs not expanding with content even though everything is set to 100% and how can this issue be resolved?

html, body {
  height: 100%;
}

body {
  margin: 0;
  padding: 0;
}

/* both of these are constrained to 100vh */
#root {
  height: 100%;
  background: #2196F3;
}

#wrapper {
  height: 100%;
  background: #2196F3;
}
#wrapper > div {
  padding: 10px;
}
<html>
  <body>
    <div id="root">
      <div id="wrapper">
        <div>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
        
        <div>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
        
        <div>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
        
        <div>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
        
        <div>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
        
        <div>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
        
        <div>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
        
        <div>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
      </div>
    </div>
  </body>
</html>

I have looked through many similar posts regarding this problem, but I couldn't find a solution that worked for me.

It may come up, so just to address it now: I am unable to use min-height due to reasons unrelated to this specific issue.

Answer №1

To improve your layout, delete the height:100% property from your #wrapper

html, body {
  height: 100%;
}

body {
  margin: 0;
  padding: 0;
}

/* this is only 100vh */
#root {
  height: 100%;
  background: #2196F3;
}

/* this is only 100vh */
#wrapper {
  
  background: #2196F3;
}
#wrapper > div {
  padding: 10px;
}
<html>
  <body>
    <div id="root">
      <div id="wrapper">
        <div>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
        
        <div>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
        
        <div>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
        
        <div>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specim...   </div>
        
        <div>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, w ...

Answer №2

Consider removing the height:100% property from your wrapper element.

html, body {
  height: 100%;
}

body {
  margin: 0;
  padding: 0;
}

/* this is only 100vh */
#root {
  height: 100%;
  background: #2196F3;
}

/* this is only 100vh */
#wrapper {
  background: #2196F3;
}
#wrapper > div {
  padding: 10px;
}
<html>
  <body>
    <div id="root">
      <div id="wrapper">
        <div>Unique text here.</div>

...

</html>

Answer №3

To create a consistent background color for every wrapper div, simply add background-color: #2196F3; to the CSS styling of #wrapper>div.

It's worth noting that you do not need to include height: 100% in the styling for both wrapper and root to achieve your desired outcome.

html,
body {
  height: 100%;
}

body {
  margin: 0;
  padding: 0;
}

#wrapper>div {
  padding: 10px;
  background: #2196F3;
}
<html>

<body>
  <div id="root">
    <div id="wrapper">
      <div>Lorem Ipsum is simply dummy text...
        (omitted for brevity)
      </div>
    </div>
  </div>
</body>

</html>

Answer №4

Straightforward fix

Incorporate the CSS rule overflow:auto to the element with ID #wrapper

This will enable the parent element to manage the overflow of its child content when it exceeds the original 100% height limit

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

Obtaining text from HTML code

Currently, I am faced with a challenge. My task involves extracting HTML text and saving it as an Anchor object. Here is an example: <html> <head> <title>{dynamihead/}</title> </head> <body> {repeatinghtml} <p>{r ...

Adjust the appearance attribute of FormField within the designated theme

Currently, I am collaborating within an NX Monorepo and utilizing a shared ui-components library that extends the capabilities of Angular Material Components. Despite using different themes for various applications, I am aiming to incorporate appearance=&a ...

What is the process for sending a request and obtaining a response from a REST API using JavaScript?

I have a private server set up on my computer with a built-in REST API. The base URL for the API is: . I am now looking to develop a client application for this server using the API. To authenticate on the server, the API endpoint is baseurl/login with the ...

Ways to incorporate or eliminate a class on a hyperlink

I am currently working with bootstrap tabs, and I have four of them. My goal is to assign a different color to each tab, which should change when the user clicks on them. Bootstrap's "active" class doesn't seem to be effective in this case becaus ...

Website navigation toolbar with access level control

I'm currently working on a website with various webpage links in the navigation menu, and I want to restrict access for non-admin users. Would it be better to set up different access levels or just use passwords on each page? What approach would be mo ...

Troubleshooting HTML Output Display Issues

I've been trying to post my content exactly as I submit it, but for some reason, it's not working. When I enter two paragraphs in a post, the output doesn't maintain that formatting. Instead, it removes the paragraph breaks and displays the ...

Reasoning behind using double colons in CSS

In the realm of CSS3, a significant change was made with the introduction of the double colon notation. This modification aimed to differentiate between pseudo-classes and pseudo-elements in styling elements [CSS3 selectors spec]. An illustration of this d ...

Utilizing GTM to Implement Dynamic Content Deployment

Can you provide guidance on the entire process from creating a Custom HTML Tag in GTM to executing JavaScript for firing dynamic HTML code, such as displaying a div with text or image based on a specific rule like the referral or cookie variable? For exam ...

Not implementing auto-scroll feature because of the presence of `position: sticky` or `position: fixed` CSS properties

I'm encountering a console warning while working on my Nextjs project. Here is the snippet of my code: <aside className={`site-off desktop-hide ${showMenu ? "show-menu" : ""}`}> .... </aside> And here is the relevant ...

Centering content within a Bootstrap 4 card deck: tips and tricks

On my Bootstrap 4 page, I'm working with a deck of cards and want to align the buttons for a better appearance. How can this be achieved? Check out the image below: https://i.sstatic.net/XkfqJ.png You can also view the demo here: The table doesn&ap ...

Scrollable carousel images with responsive design in bootstrap on mobile devices

While working with a responsive Bootstrap carousel, I've encountered an issue where there is a 'scroll' on mobile devices. Can anyone provide some helpful suggestions on how to resolve this? You can view the carousel in question at this lin ...

Creating an adaptable image with CSS or Material UI

Is it possible to create a responsive image that shifts from the top right position to the bottom as the size decreases? I've been using Material UI but haven't found any guidance on how to achieve this. .my-photo{ height: 300px; positio ...

Issue with the alignment of two rows in an HTML template

I'm encountering an issue with the spacing between two rows/elements in an HTML template. I'm working on creating a product grid for our restaurant and used a template sourced from the Internet. As shown in this picture: issue1 The problem lies ...

AngularJS allows us to easily include the route provider templateUrl path in the view div, making

I have the following route provider setup: $routeProvider .when('/', { templateUrl: '/slapppoc/Style Library/TAC/Views/tarification/home.html', controller: 'homeController' /* resolve: { // This f ...

Send the user back to the homepage without the need to refresh the page

When the user clicks "Okay" in my window.prompt, the code below opens a new tab. Is there a way to direct the user to the home page without opening a new tab? if (window.confirm("Do you really want to leave?")) { window.open("./Tutoria ...

Showing information from a database query

Let's say we have a form that submits data to the dataprocess.php file after submission. The dataprocess.php file processes the form variables and outputs the desired results. It can be challenging to directly echo content into a specific div on a pa ...

Tips for displaying reCaptcha responses above or below the contact form

Previously, @ADyson provided a solution on how to display returns on a new page. I appreciate the help, but I would prefer to see it under the contact form on that specific contact page. I was advised to use an echo statement and an if statement, which I&a ...

Creating an HTML drop-down menu for selecting a vehicle

I am looking to incorporate two drop down menus on my website. One for selecting car brands and the other for choosing specific car models. I have successfully set up the drop down menu for car brands, but it currently only displays four options: Maruti Sw ...

Tips for eliminating excessive line breaks when incorporating a table tag into nl2br

In my dataset, I have content that consists of plain text, codes, and tables interchangeably. To keep the database optimized, I have limited the use of HTML tags by excluding pre tag for table and text, reserving it only for codes (spaces do not need to b ...

In JavaScript, attempting to trigger a click event on an element with a <ul> and <li id> and <a href>, but only after the <li id> has been selected

Apologies if this question is too basic, I've been struggling with it for some time... I am trying to trigger an <a href> from within a tag. I have found several methods to do so, however... the entire script is contained within a <ul>, ...