The sidebar 100vh is not extending in length

I am facing an issue with the sidebar on my website. The sidebar has a fixed height of 100vh, but when the content exceeds the viewport height and requires scrolling, the sidebar does not extend along with the page. How can I fix this layout problem?

html {
  line-height: 1.15;
  -webkit-text-size-adjust: 100%;
  font-family: 'Roboto', sans- serif;
  box-sizing: border-box;
  min-height: 100%;
}

*,
*:before,
*:after {
  box-sizing: inherit;
}

body {
  margin: 0;
}

.container {
  height: 100%;
}

.sidebar {
  height: 100vh;
  background-color: #c7cdd1;
}
<div class="container">
  <div class="sidebar"></div>
  <div class="content"></div>
</div>

Answer №1

My solution involved adjusting the height to 100% using absolute positioning

Answer №2

Explanation: (Ensure to read this attentively for better comprehension of the code!!!)

To start, you need to assign the width property to both the sidebar and the content sections. As mentioned earlier, the content will have a width: 65%; property, while the .sidebar will have a width: 35%; property. Ensuring their total widths sum up to 100% eliminates any space between them.

Furthermore, it's essential to use the float property so that they align next to each other rather than one below the other. This is achieved by applying .content{float: left;} and .sidebar{float: right;}. By implementing this approach, they are effectively divided into 35-65%, and regardless of the containers' assigned height property, they will expand accordingly. Trust this explanation demonstrates clarity on the topic.

Take a close look at the code snippet provided below for a detailed understanding.

html {
  line-height: 1.15;
  -webkit-text-size-adjust: 100%;
  font-family: "Roboto", sans-serif;
  box-sizing: border-box;
}

*,
*:before,
*:after {
  box-sizing: inherit;
}

body {
  margin: 0;
  background-color: black;
}

.container {
  height: 500px;
}
.content {
  background-color: pink;
  height: 500px;
  width: 60%;
  float: left;
  font-size: 50px;
}

.sidebar {
  background-color: blue;
  height: 500px;
  width: 40%;
  float: right;
  font-size: 50px;
}
<div class="container">
  <div class="sidebar">This is sidebar</div>
  <div class="content">This is content</div>
</div>

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 it possible to personalize a select button for both iOS and Android mobile platforms?

I've implemented a dropdown on my website for the desktop version and it works fine. However, I want to replace this dropdown with a select button on iPad and iPhone, as I prefer how it looks on those devices. Is it possible to style the select butto ...

passing a javascript variable to html

I am facing an issue with two files, filter.html and filter.js. The file filter.html contains a div with the id "test", while the file filter.js has a variable named "finishedHTML." My objective is to inject the content of "finishedHTML" into the test div ...

How to strategically break Bootstrap 5 button groups for different resolutions?

Is there a way to create a line break in a specific place within a button group on a certain screen size? I have a button group with 4 buttons in a row, and I would like to split it into two lines after the first button if there isn't enough space. ...

Fluid Bootstrap Container Experiencing Alignment Issues with Rows when CSS Height Property set to 100%

My Bootstrap container has a fluid width and I'm trying to align three rows within a sidebar to sit at the top, middle, and bottom. I came across this demo in the Bootstrap documentation which shows how to do it for full-width layout, but I need it fo ...

Is there a way to confine a jquery script within the dimensions of the container div?

I have recently created a gallery with navigation buttons in jQuery. As a newcomer to jQuery, I wrote a small script that adjusts the margin of a div container by a fixed amount. The script is functioning properly, but it extends beyond the top and bottom ...

Embed the svg element within a specified class

I am seeking guidance on how to insert an SVG that I created into a CSS or SCSS class, so that only the class is assigned to the icon, similar to this example from W3Schools: <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> ...

Is there a way to manipulate the placement of an image within a div using CSS?

Teaching myself HTML has been quite the journey. Right now, I'm in the process of building a website purely for its aesthetic appeal, and I seem to be hitting a roadblock with the CSS/div element. As of now, it appears like this. When the h1 is remove ...

Using a forward slash in the path for the href attribute in a CSS link within an ejs file

Image 1: Configuring express.static for the public folder Image 2: Adding href="/app.css" in post.ejs file Image 3: Final result While experimenting with using /app.css and app.css in the post.ejs file, I noticed that the outcome was consistent with th ...

Styling PHP Input Buttons with CSS

I'm facing an issue with styling the button on a working form. Even though I added CSS and declared the button class, it's not applying the styles. The CSS is defined at the top of the HTML file, and the PHP code is embedded within. Both classes ...

Display user's name in navigation bar using asp.net mvc

When working on an ASP.NET MVC project, I wanted to include a short message for the user, such as 'Hello, username!' In the navigation bar, specifically when the user is signed in, I encountered some display issues with the standard bootstrap la ...

Do mouse users prefer larger buttons on RWD sites for a better experience?

Not entirely certain if this platform is the most suitable for posing this query, so if warranted, please close it and recommend a more appropriate venue for such inquiries. In the realm of responsive web design (RWD) today, it is common practice for webs ...

The button should only be visible on an iPhone device

Currently, I am utilizing the Twitter Bootstrap layout and facing an issue. When I reduce the browser window size, a menu should appear only for iPhone layout when clicking a button. However, the button is showing up for desktop as well. How can this be fi ...

Looking for assistance with CSS selectors for the following structure

I am currently working on locating the anchor element "a" that is nested inside a table with the class name table.ic-table-creditReportProduct table tr. I have attempted to find it, but my attempts have been unsuccessful so far. Any suggestions on where th ...

What is the best way to assign a background color to each tr element using JavaScript?

I have a list of table rows with different background colors like <tr bgcolor="#OC6110"> <tr bgcolor="#000000"> <tr bgcolor="#FFFFFF"> Is there a way to assign unique background colors to each tr element without specifying its id value ...

What's the best way to make sure an image in CSS respects the height of its parent flexbox section?

This question addresses a clear problem: Flexbox - Img height conflict. However, the accepted answer does not meet my specific needs. One potential solution involves using absolute and relative positioning. While this resolves sizing issues, it interferes ...

steps for centering an image on an ionic page

Is there a way to center an image (logo) both horizontally and vertically on the page? <ion-view hide-nav-bar="true"> <ion-content class="backgound-red "> <section class = "home-container"> <div class="row icon-row"> ...

When the Button is clicked, scroll the element to the top position

I want to include an "ADD COMMENT" button on my page. When clicked, a form will be displayed for users to add comments. I would like the form to automatically scroll to the top position of the page so that users do not have to manually scroll down to vie ...

The CSS Specificity Hierarchy

I am currently facing a dilemma with two CSS classes in my codebase. Despite having a stronger specificity, the second class is not being chosen over the first one. Can anyone shed some light on this issue? The CSS class that is currently being applied is ...

Adjust the class based on the model's value in AngularJS

items = {'apple', 'banana', 'lemon', 'cat', 'dog', 'monkey', 'tom', 'john', 'baby'} html <div class="variable" ng-repeat="item in items">{{item}} </div> ...

Bootstrap-4 grid system is effectively maintaining its responsiveness without collapsing

I'm struggling to display one image per row on smaller screens using the sm breakpoint. This is my first attempt at using bootstrap 4. I followed their grid system guidelines which stated that responsive breaks occur when specifying a size for each c ...