Maintain the full height of the side bar

My CSS skills aren't the best, so I'm struggling to keep my sidebar at full height even when it doesn't have enough content. Here's my current CSS:

#wrapper {
display: flex;
flex-wrap: wrap;
background-color: yellow;
}

#wrapper .sideBar { 
background-color: green;
width: 200px;
margin-left: 10px;
overflow-x: hidden;
padding-top: 20px;
}

#wrapper .productsBox{
width: 250px;
margin: 3px;
}

The result I'm currently getting ishttps://i.sstatic.net/j4MhM.png

However, I'm aiming for a layout that looks like this: https://i.sstatic.net/bXs4i.png

Any suggestions on how I can achieve this? Also, I want it to be responsive so that it displays well on mobile devices. That's why I'm using the wrapper. html:

<div id="wrapper">
   <form method="get" id="sortForm">
        @Html.DropDownList("sort", new SelectList(ViewBag.sortOptions,"Value","Text"), new {@class="form-control", onchange = "sortingChanged()" })
    <div class="sideBar">
            <strong>Search for products</strong>
            <input type="text" class="searchBar" name="SearchString" value="@ViewData["CurrentFilter"]" placeholder="Search.."/>            
        <hr />
        <h6>Price</h6>
            <div>
                <input type="number" class="priceRangeInput" name="minPrice" value="@ViewData["MinPriceFilter"]" oninput="validity.valid||(value='');"  />
                <span>Min</span>
            </div>
            <div>
                <input type="number" class="priceRangeInput" name="maxPrice" value="@ViewData["MaxPriceFilter"]" oninput="validity.valid||(value='');" />
                <span>Max</span>
            </div>
            <br />
            <hr>
        <h6>Types</h6>
        

            <button type="submit" class="btn customGreen" >Set filters</button>

        </form>
        
        <br />
    </div>
    

        @{

            foreach(var p in @Model)
            {
                <div class="productsBox">
                <div class="card">
                <a asp-action="Details" asp-route-id="@p.Id">
                    <img alt="@p.Name" class="contain" src="@p.FilePath" height="300" style="width: 100%;" />
                </a>
                <h3>@p.Name</h3>
                <p class="price">@p.Price kr/@p.Unit</p>
                <a asp-action="Details" asp-route-id="@p.Id">
                    <button class="customGreen">See more</button>
                </a>
            </div>
            </div>
            }
            
        }
        
</div>

Answer №1

html, body {
  height: 100%
}

html,
body {
  height: 100%; /* to set height to 100% */
}

body {
  margin: 0; /* to remove default margins */
}

.wrapper {
  height: 100%; /* to set height to 100% */
}

.wrapper {
  display: flex;
  background-color: yellow;
}

.sideBar {
  background-color: #000;
  width: 200px;
  color: #fff;
  overflow-x: hidden;
  padding-top: 20px;
}

.product-wrapper {
  width: calc(100% - 200px); /* 100% - (sidebar width) */
}

.productsBox {
  display: inline-block;
  width: 150px;
  height: 150px;
  color: #fff;
  margin: 3px;
  background: #2f910f;
}
<html>
<body>
  <div class="wrapper">
    <div class="sideBar">
      Sidebar
    </div>
    <div class="product-wrapper">
      <div class="productsBox">
        Item
      </div>
    </div>
  </div>

</body>

</html>

Answer №2

To ensure that the contents of your website do not go under the sidebar, consider moving the .sideBar element outside of the #wrapper container. Instead, apply a width of calc(100% - 210px) to the #wrapper. This way, both elements will occupy 100% of the width, with the sidebar accounted for separately. This will help maintain the layout integrity of your website.

Answer №3

It's a good idea to enhance the layout by adding a sidebar and other content in separate divs. Here is some code you can use:

.main-wrapper{
  display:flex;
  flex-direction:row;
}
.sidebar{
  background-color:blue;
  width:30%;
}
.content{
  width:70%;
  background-color:yellow;
  
}
<div class="main-wrapper">
  <div class="sidebar">
    Sidebar Content
  </div>
  <div class="content">
    Main Content
  </div>
</div>

Answer №4

Try incorporating this snippet into your CSS - it did the trick for me:

height: 100%;

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

One div's content is merging with another div

<main> <!-- Carosel--> <div> <div class="carousel"> <button class="carousel__button carousel__button--left is-hidden"> <img src="Image/left-arrow-svgrepo ...

Using Bootstrap 4, you can create nested rows that will automatically expand to fill their parent container, which in turn has been set

In my current setup, I have a div with the class "d-flex flex-column" that contains a navbar and a container. Within this container, there is another div with the class "d-flex flex-column" which then contains two rows. I am using flex-grow to make the con ...

Tips for preloading a small placeholder image before the main content is loaded

After browsing , I noticed an interesting image loading style. The website initially shows a patterned image before revealing the actual content. This method creates visually appealing content while waiting for the entire webpage to load. Upon inspecting ...

Improper height of MathJax in the div element

I'm currently investigating why the MathJax render block is giving me an incorrect height for the div. Here's the code snippet: <div class="text-field" id='inner-text'>\(\sqrt{b^{a}\frac{\partial y}{& ...

Problems with the navigation bar scrolling in Bootstrap

The project I'm currently working on is located at zarwanhashem.com If you'd like to see my previous question along with the code, you can check it out here: Bootstrap one page website theme formatting problems Although the selected answer help ...

Ways to enable smooth scrolling feature in Safari

I attempted to implement smoothscroll using a polyfill by adding the following code to the bottom of my body tag: <script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e99a8486869d819a8a9b868585c ...

Centered background position for CSS h2

Hey there! I've got this CSS code for my H2 heading: .rightBox h2 { background: url(images/lineh2.png) 0px 0px no-repeat; border-top: 1px solid #e4e4e4; margin-bottom: 15px; font-size: 22px; font-weight: 100; font-family: "Seg ...

Toggle the visibility of three different div elements using JavaScript on mouseover

Trying to create three image links that display different divs when onMouseOver. <script type="text/javascript> function toggleVisibility(divid) { if (divid==="1"){ document.getElementById("1b").style.visibility = "visible"; document.getElem ...

Displaying a dynamic progress bar across all elements in fullscreen mode

I am looking to implement a full-screen indeterminate progress bar that overlays all screen elements. Here is my specific use case: When a user fills out a form, including an email field, the email id is checked against a database via ajax. While waiting ...

How can you activate CSS intellisense for ASP.NET .cshtml files in VS Code?

Recently, I added the "HTML CSS Support" extension to my VS Code, but it seems like it's only compatible with files having a .html extension. Unfortunately, I've been facing difficulties in getting it to work properly with .cshtml files unless I ...

Attempting to adjust the navbar dimensions, alter the size of the font, and align the text in the center

I need help with creating a responsive navbar for my website. I have been working on the CSS to adjust the size of the navbar and align the text properly, but I'm struggling to get it right. Here is a snippet of the CSS: .nav { font-family: "Ind ...

Adjustable centralized menu with buttons that resize accordingly

I am currently working on making a webpage responsive. I have successfully created a logo div that resizes accordingly. Now, I am facing a challenge with centering the buttons in the menu list. Despite my efforts, the buttons are not aligning in the center ...

Header bar/navigation bar that is constantly changing

Hi there, I'm in the process of creating a dynamic header/navigation bar similar to the one on this website: Here's what I have so far: Jquery: $(document).ready(function() { var lock = $('#header').position().top; $(window).scroll(f ...

Leverage the power of Bootstrap's col-push and col-pull

Here is the code snippet I am currently working with: <div class="col-md-9 col-md-offset-3"> <div class="row> <div class="col-sm-4 col-sm-push-4"></div> <div class="col-sm-8 col-sm-pull-8"></div> </div> ...

Internet Explorer experiencing off-screen menu loading issue

Currently, I am in the process of developing a website for my sister but facing challenges with cross-browser compatibility. The menu appears off-screen when using Internet Explorer, while it looks fine on Chrome. Despite various attempts to adjust alignme ...

Stylish Tabbed Design

Imagine I have this html and css snippet h1{ color: rgb(61, 133, 200); font-size: 3em; margin-left: 0px !important; } h1 ~ *:not(h1) { margin-left: 0px; } h2{ font-size: 1.8em; margin-left: 40px !important; } h2 ~ *:not(h2) { ...

The Material UI - makeStyles function is having difficulties generating the intended styles

After implementing withStyles and makeStyles from material-UI, I encountered an issue where the CSS styling was not as expected, despite the correct class name being returned. For example, consider the following component: import React, { Component } fro ...

Hide and show submenus with jQuery while ensuring that the initial submenu remains visible, along with the main menu

I am struggling to figure out how to make the first message active by default along with its corresponding menu selection in my navbar. I have implemented a show/hide functionality on the main menu click, but currently only the menu is being set as active ...

What is the best method for incorporating dynamic page transitions when navigating between individual pages?

Let's say I have the following pages: red.html blue.html green.html My goal is to create links from red.html to blue.html and red.html to green.html. When attempting to use page anchors and iframes, I encountered an issue where scrolling from red.h ...

Combining :not() and :first-child in element selection is not supported

While working on CSS, I encountered an issue. I am using a combination of :not(.class) selector and :first-child selector. Individually they work fine. The row that should be red is not turning red. Here is the code snippet: table tr td { background: ...