The height of the <ul> element does not adjust to accommodate its child <li> elements

The <ul> on my page has a height:100%, but it doesn't dynamically adjust to fit all of its <li> child elements.

This is what's happening:

  • When scrolling through the list, you'll notice that the background color for the <ul> does not extend to the bottom of the last <li>.

This is what I want to happen:

  • I'm looking for a scrollable <ul> element that wraps around and contains all the <li> items.

Additional Information:

  • There's a parent <div> that encompasses the unordered list (<ul>) consisting of individual items in the form of a label <label> and an input field <input>. All of this content is positioned between a header (<header>) and footer (<footer>).

You can view the CodePen example here.

* {
  border: 0;
  font-family: "Lucida Console", Monaco, monospace
}
body {
  min-width: 1440px;
  height: 100%;
  //background: #bbb
}
header {
  width: 100%;
  height: 60px;
  background: #bada55;
  margin: 0;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  //opacity: .4;
}
footer {
  width: 100%;
  height: 100px;
  background: #bada55;
  margin: 0;
  position: fixed;
  bottom: 0;
  left: 0;
  z-index: 100;
  //opacity: .4;
}
ul,
li {
  list-style-type: none;
  color: #444;
  display: block;
}
label,
input {
  display: block;
  position: relative;
}
#wrap {
  background: #000;
  width: 40%;
  height: 100%;
  position: absolute;
  margin: 0;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
#question_list {
  width: 100%;
  min-width: 452px;
  height: 100%;
  background: #bada55;
  padding: 0;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
}
.question {
  background: #ddd;
  width: 90%;
  height: 120px;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  margin: 0
}
.question label {
  font-size: 24px;
  text-align: center;
}
.question input {
  width: 284px;
  left: 50%;
  transform: translateX(-50%);
  border-radius: 4px;
  font-size: 24px;
  margin-top: 44px;
  margin-bottom: 24px
}
.space {
  width: 100%;
  height: 120px;
  background: #badff5
}
<header></header>
<div id="wrap">
  <ul id="question_list">
    <li id="space_0" class="space"></li>
    <li id="one" class="question">
      <label for="f_name">First Name</label>
      <input name="f_name" id="f_name" />
    </li>
    <li id="space_1" class="space"></li>
    <li id="two" class="question">
      <label for="l_name">Last Name</label>
      <input name="l_name" id="l_name" />
    </li>
    <li id="space_2" class="space"></li>
    <li id="three" class="question">
      <label for="age">Age</label>
      <input name="age" id="age" />
    </li>
    <li id="space_3" class="space"></li>
    <li id="four" class="question">
      <label for="address">Address</label>
      <input name="address" id="address" />
    </li>
    <li id="space_4" class="space"></li>
    <li id="five" class="question">
      <label for="degree">Degree</label>
      <input name="degree" id="degree" />
    </li>
    <li id="space_5" class="space"></li>
    <li id="six" class="question">
      <label for="exp">Years of Experience</label>
      <input name="exp" id="exp" />
    </li>
    <li id="space_6" class="space"></li>
  </ul>
</div>
<footer></footer>

Answer №1

To achieve the desired outcome, simply include this basic CSS rule:

ul {
  overflow: auto;
}

For more information on the overflow CSS property, visit this link

View a sample demonstration on CodePen 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

Is there a method to retrieve fresh data in HTML without the need to restart the server?

I am encountering an issue with my node.js express server. I have an audio file that is being recorded every 5 seconds on my Raspberry Pi with the same name. The problem arises when I try to play this audio file on my website, which refreshes every 10 seco ...

What methods can I use to ensure that content is not obstructed by the Android virtual keyboard? Leveraging Bootstrap

I am currently tackling an issue with my 'navbar' layout that looks like this: <nav class="navbar navbar-expand-lg navbar-dark bg-dark"> <button class="navbar-toggler" type="button" data-toggle="collaps ...

What is the best way to create an href that points to the parent directory?

I am facing an issue with the HTML page located at the following URL: http://localhost:63343/x/html_pages/http_failures_table/http_failures_table_agg_bl.html The hyperlink is set as: <a href="../http_failures_dict/http_failures_dict_bl_0.txt"> How ...

Problem with nested table columns not extending to full height of parent table

I'm currently facing an issue with my HTML table. The nested table on the right does not occupy the full height of the main table. Even if the content in the description column is short, I want the column to resize accordingly. I have tried various ...

What causes an element with position:absolute to be placed behind the ::after pseudo-element?

Being a beginner in HTML and CSS, I recently encountered a challenge while working on some exercises. My goal was to create a website with a blur effect, so I decided to design a header with the class "showcase" and nested inside it, a div with the class " ...

How can a single item from each row be chosen by selecting the last item in the list with the radio button?

How can I ensure that only one item is selected from each row in the list when using radio buttons? <?php $i = 1; ?> @foreach ($products as $product) <tr> <td scope="row">{{ $i++ }}</td> <td>{{ ...

Is it possible to design a div with a curved lower edge?

As I am developing a website, I have a question regarding the styling of a div element. Is it achievable using just HTML5, CSS3 (and possibly JavaScript) to create a div with a curved bottom like the one shown below: https://i.sstatic.net/ZfM0a.png Or wo ...

Vuetify: how to disable the color transition for v-icon

My menu includes both icon and text items, with hover color styled using the following CSS: .v-list-item:hover { background: #0091DA; } .v-list-item:hover .v-list-item__title, .v-list-item:hover .v-icon { color: white; } The problem is that the ...

What is preventing the ":last-child" selector from working when the parent element is <body>?

Here is a basic HTML structure: <body> <a> <div>1</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> </a> </body> The divs are nested within ...

Is there a way to toggle the visibility of the angular material toolbar at regular intervals?

I'm currently experimenting with the CSS animation feature to display and conceal the angular material toolbar in this demonstration. Inside the application component, the hide attribute is toggled at intervals as shown below: hide:boolean = false ...

Interactive Geography Selector

When updating your personal details on , you are required to choose your country first. Once the country is selected, the system automatically adjusts the city and/or state options based on that specific country's requirements. Can someone provide exa ...

Maintaining text in a straight line

My design includes an image floated to the left with text aligned to the right of the image. Unfortunately, the text is too long, causing a line from a paragraph to drop below the image. How can I ensure that the text stays in line with the paragraph and ...

CSS Styling for a Minimalist Web Design

I have been working on creating my own layout for a few hours now, but I am still encountering some issues. My goal is to achieve something like this: Specifically, I want the body of the page to be flexible, with a maximum width of 900px. However, I am s ...

What is the best method for determining the current value of an On/Off switch with labels for both states?

How can I retrieve the current value of an On/Off switch that is labeled as On and Off? Below is the HTML code for this particular switch: <div class="make-switch has-switch"> <div class="switch-on switch-animate"> <input type="checkbox" d ...

What is the best way to remove $_GET parameters using "href"?

On my search results page at www.mysite.com/?search=test, I have an a tag. I want to be able to refresh the page and remove all the $_GET variables from the URL by clicking the <a> link. Currently, I am using a simple <a href="?"> but ...

Tips for aligning a single item to the center in a Bootstrap navigation bar that has the majority of items on the right

I am attempting to center the text "Welcome:" within the navbar without center aligning the entire navbar. I want the navbar to remain right aligned, but only the "Welcome:" portion should be centered. Here is what I have tried so far... <!DOCTYPE html ...

What is the best way to incorporate web components into a React Js project?

I am currently unfamiliar with web components. My main goal is to integrate Google Material Components into my React.js project. Google Material Web Component can be found here: https://github.com/material-components/material-components-web Is there a ...

JS switch for numerous container elements

How can I create a toggle slider in HTML for multiple elements displayed using foreach? Each element should open a div block with specific information and have a close button. Unfortunately, I haven't been able to find any suitable code to achieve thi ...

The input field is lacking in showing icons on the screen

Looking for some help with my code. I'm trying to display a bootstrap icon instead of a button. Can anyone spot what's causing the issue? <input type="submit" value="Update" class="btn btn-default btn-update" /> I attempted the following ...

Adjusting the code in Java and PHP

I'm trying to update this code because it was originally designed for .asp files, but now my document is in .php However, the script is causing some issues for me. What I really want to do is calculate how many days have passed since March 21st, 1858 ...