Tips for adjusting a div height to match the height of a scrollable page

I am currently working on creating a website with a store-like layout, and I have been facing an issue while implementing a sidebar for the categories. No matter what I try, I can't seem to make the sidebar height reach the end of the page. It remains too small even after resizing.

I've experimented with adjusting the height property but haven't found a solution yet. I attempted using position: fixed, but that caused the sidebar to overlap with my header. My goal is to have the sidebar extend all the way down to the bottom of the page, regardless of resizing.

#categories ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  width: 205px;
  background-color: orange;
  float: left;
  height: 100vh;
}

#categories li h2{
  text-align: center;
}

#categories li a{
  display: block;
  color: black;
  padding: 15px 35px;
  text-decoration: none;
}

#categories li a:hover{
  background-color: black;
  color: white;
}

/* ----------------------------------------------------------------------------------------- */

#products{
  background-color: darkred;
  border-style: solid;
}

#products ul{
  list-style-type: none;
}

#products li{
  padding-bottom: 75px;
  border-bottom: solid;
}

#products li img{
  width: 227px;
  float: left;
}
<body>

  <div id="categories">
    <ul>
      <li><h2> Larem Ipsum </h2></li> <!-- Category Titles -->
 
      
      <li><a href="#1">1</a></li>
      <li><a href="#2">2</a></li>
      <li><a href="#3">3</a></li>
      <li><a href="#4">4</a></li>
      <li><a href="#6">5</a></li>
    </ul>
  </div>


  <div id="products">
    <ul>
      <li>
        <img src="https://www.freeiconspng.com/thumbs/photography-icon-png/img-landscape-photo-photography-picture-icon-12.png">
        <h2> Lorem ipsum dolor sit amet </h2>
        <h3> Lorum Ipsum Cacetes Cacetinhos! </h3>
        <h1> 3.99€ </h1>
      </li>
      
      <li>
        <img src="https://www.freeiconspng.com/thumbs/photography-icon-png/img-landscape-photo-photography-picture-icon-12.png">
        <h2> Lorem ipsum dolor sit amet </h2>
        <h3> Quisque sapien ligula, gravida ac magna ac, </h3>
        <h1> €€€ </h1>
      </li>
      
      <li>
        <img src="https://www.freeiconspng.com/thumbs/photography-icon-png/img-landscape-photo-photography-picture-icon-12.png">
        <h2> Lorem ipsum dolor sit amet </h2>
        <h3> Quisque sapien ligula, gravida ac magna ac, </h3>
        <h1> €€€ </h1>
      </li>
      
      <li>
        <img src="https://www.freeiconspng.com/thumbs/photography-icon-png/img-landscape-photo-photography-picture-icon-12.png">
        <h2> Lorem ipsum dolor sit amet </h2>
        <h3> Quisque sapien ligula, gravida ac magna ac, </h3>
        <h1> €€€ </h1>
      </li>
      
      <li>
        <img src="https://www.freeiconspng.com/thumbs/photography-icon-png/img-landscape-photo-photography-picture-icon-12.png">
        <h2> Lorem ipsum dolor sit amet </h2>
        <h3> Quisque sapien ligula, gravida ac magna ac, </h3>
        <h1> €€€ </h1>
      </li>
      
    </ul>
  </div>
  
</body>

Link to the fiddle: https://jsfiddle.net/r4jp8ocn/

Answer №1

I grouped both parts into a container using the flex property. To make sure the side menu stays in place, I applied the position: sticky rule. All changes have been detailed in the CSS code.

I hope this explanation was helpful for you.

body {
  box-sizing: border-box; /*Include this line*/
  margin: 0; /*Include this line*/
  padding: 0; /*Include this line*/
}

.container {
  display: flex; /*Include this line*/
}

#categories ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  width: 205px;
  background-color: orange;
  float: left;
  height: 100vh;
  
  position: sticky; /*Include this line*/
  top: 0; /*Include this line*/
}

#categories li h2{
  text-align: center;
}

#categories li a{
  display: block;
  color: black;
  padding: 15px 35px;
  text-decoration: none;
}

#categories li a:hover{
  background-color: black;
  color: white;
}

/* ----------------------------------------------------------------------------------------- */

#products{
  background-color: darkred;
  border-style: solid;
  flex: 1; /*Include this line*/
}

#products ul{
  list-style-type: none;
}

#products li{
  padding-bottom: 75px;
  border-bottom: solid;
}

#products li img{
  width: 227px;
  float: left;
}
<body>

  <div class="container">



<div id="categories">
    <ul>
      <li><h2> Larem Ipsum </h2></li> <!-- Category title-->
 
      
      <li><a href="#1">1</a></li>
      <li><a href="#2">2</a></li>
      <li><a href="#3">3</a></li>
      <li><a href="#4">4</a></li>
      <li><a href="#6">5</a></li>
    </ul>
  </div>


  <div id="products">
    <ul>
      <li>
        <img src="https://www.freeiconspng.com/thumbs/photography-icon-png/img-landscape-photo-photography-picture-icon-12.png">
        <h2> Lorem ipsum dolor sit amet </h2>
        <h3> Lorum Ipsum Cacetes Cacetinhos! </h3>
        <h1> 3.99€ </h1>
      </li>
      
      <li>
        <img src="https://www.freeiconspng.com/thumbs/photography-icon-png/img-landscape-photo-photography-picture-icon-12.png">
        <h2> Lorem ipsum dolor sit amet </h2>
        <h3> Quisque sapien ligula, gravida ac magna ac, </h3>
        <h1> €€€ </h1>
      </li>
      
      <li>
        <img src="https://www.freeiconspng.com/thumbs/photography-icon-png/img-landscape-photo-photography-picture-icon-12.png">
        <h2> Lorem ipsum dolor sit amet </h2>
        <h3> Quisque sapien ligula, gravida ac magna ac, </h3>
        <h1> €€€ </h1>
      </li>
      
      <li>
        <img src="https://www.freeiconspng.com/thumbs/photography-icon-png/img-landscape-photo-photography-picture-icon-12.png">
        <h2> Lorem ipsum dolor sit amet </h2>
        <h3> Quisque sapien ligula, gravida ac magna ac, </h3>
        <h1> €€€ </h1>
      </li>
      
      <li>
        <img src="https://www.freeiconspng.com/thumbs/photography-icon-png/img-landscape-photo-photography-picture-icon-12.png">
        <h2> Lorem ipsum dolor sit amet </h2>
        <h3> Quisque sapien ligula, gravida ac magna ac, </h3>
        <h1> €€€ </h1>
      </li>
      
    </ul>
  </div>
  </div>
  
</body>

Answer №2

Hey there! To style the elements properly, you should apply the CSS to the specified IDs below:

#products {
background-color: darkred;
border-style: solid;
float: right;
width: 60%;
}



 #categories {
    float: left;
    width: 40%;
}

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

Striking a balance between innovation and backward compatibility in the realm of Web Design/Development

Creating websites is my passion, and I enjoy optimizing them for various platforms, devices, and browsers. However, lately, I've been feeling frustrated. I'm tired of facing limitations in implementing my creative ideas due to outdated technolog ...

modifying meta descriptions dynamically using c# code

On my webpage, I have a meta description tag that I am trying to change programmatically using the following code: <meta name="description" content=<%=getmeta()%> /> The getmeta function is implemented as shown below: public string getme ...

CSS background property does not function properly if the URL contains brackets

Here is the URL for an image I am working with: URL: Currently, I am having an issue in my CSS: background: url(http://www.andrearosseti.cl/image/cache/data/New%20Coleccion/Planas/SWEET-5-TAUPE-(1)-340x340.jpg) The problem arises due to the presence of ...

Creating an iframe in JavaScript with a document is a simple task that involves a few

My goal is to dynamically create an iframe element using JavaScript that includes a <head> and <body>. It is crucial that the iframe remains hidden in the DOM. I have made several unsuccessful attempts at achieving this: var frame = $(' ...

Considering the edges when positioning objects (aligning and justifying)

Check out my code snippet here: https://play.tailwindcss.com/6e1ovq2LZC?layout=preview (make sure to set your browser's zoom to 500%) Here is a visualization of how the input with the buttons appears The issue I'm facing is that the left border ...

jQuery tooltip functionality allows you to easily add tooltips to

Recently, I incorporated the jTip Theme for tooltip into my website using guidance from this site. Currently, the tooltip only closes when the close icon is clicked. However, I am looking to enhance this functionality by enabling users to also close the ...

Searching for non-existent PHP index with $_POST superglobal

How can I resolve the issue of encountering an undefined index? Each time I submit without checking the box, I receive an error regarding undefined index. <html> <head> <title>Order</Title> <style> ...

How does altering the flex direction impact the height of the child elements?

I am currently attempting to create a media query using Flexbox in order to display an input element below another one instead of side by side. However, the issue I am facing is that when I set the flex-direction to column, the width of the input is not as ...

In my Flask Bootstrap website, the navigation bar remains unchanged by the presence of Javascript

I am currently in the process of creating a navigation bar for my Flask website using Bootstrap. However, when I implemented it into my HTML code, it is not displaying correctly which leads me to believe that the JavaScript may not be functioning properly. ...

Expanding the jQuery vertical tab content section to span the entire width of the page

I set up a vertical tab interface following the instructions here, but I'm having trouble with the content area not extending all the way across the page. I've been experimenting with adjusting the CSS by adding width='100%' attributes ...

Duplicate CSS designed file upload buttons

I have used CSS to style an input type file. Whenever I click on a plus button, it duplicates the input field. However, this duplication only visually happens with an unstyled upload button. Hint: To replace the standard button with a styled one, I hide i ...

The onclick function appears to be ineffective when used on a button loaded via Ajax

I have a situation with my website where, upon selecting a day, some forms are loaded via an Ajax request. Inside this loaded content (which I add to a modal), there is a button <button class="btn btn-success" type="button" onclick="addInput()" name=" ...

Generate random unique values from an array to populate a text input field in HTML. Display a message once all unique values have been shown

I have included an option code and text box below: <select id="sel" class="form-control input-lg" data-live-search="true"> <option value="">-- Choose Your Country--</option> </select><br/><br/><br/> &l ...

What is the best way to navigate through images only when hovering?

I have a website that showcases a collection of images in a creative mosaic layout. Upon page load, I assign an array of image links to each image div using data attributes. This means that every image in the mosaic has an associated array of image links. ...

Converting CSS to LESS with multiple classes sharing the same properties: step-by-step guide

I have some CSS code here that I'd like to convert into LESS format. Can you help me with that? .A .B h4, .A .B h4 a, .A .C h4, .A .C h4 a, .D h4, .D h4 a { color: #345e8a !important; display: inline-block; font-family: @font-family-sans ...

What is the best method for creating numbered paragraphs using HTML5 and CSS3?

Currently, I am putting together a QuickBASIC 4.5 manual in HTML5 and have made progress with it. However, I am looking for a way to add line numbers or prevent text wrapping in my code snippets. The current format of my code is as follows: 1. PRINT "Hell ...

How to Automatically Display the First Tab in Bootstrap 3

Having a dynamic modal with two tabs, I aim for #tab1 to always be the default tab upon opening the modal. The issue arises when the modal is opened, #tab2 is clicked, and then the modal is closed. Subsequent reopenings still display #tab2. See JSFiddle e ...

"Which is better for handling form data: using $.ajax with hidden fields or PHP form

Creating a streamlined admin tool using PHP and JQuery to handle image data management is my current project. The main goal of this utility is to enable an admin to retrieve images from a database, view associated tags for each image, and add new tags as n ...

"Utilizing Bootstrap to ensure content is aligned perfectly to the baseline

I've been struggling to align my contents to the baseline while working with the bootstrap framework. I tried following the instructions in the documentation, but it didn't work out as expected. <div class="row"> <div class="col-12 ...

Creating an XPath expression for selecting multiple siblings of a div tag

Currently, I am working on writing an XPath expression for a specific section of code: <div class="line info"> <div class="unit labelInfo TextMdB">First</div> <div class="unit lastUnit"> <div clas ...