Creating a div with relative positioning and a height of 100% in Bootstrap

I am attempting to design a left sidebar on my webpage with the main content positioned to the right of it. However, I am facing an issue where setting the sidebar div to 100% height requires using position: absolute; which causes the content to overlap the sidebar.

Below is my HTML code:

<div class="row">
  <div class="sidebar col-sm-3">
    <ul>
      <li class="active">
        <h3><a href="">Link</a></h3>
      </li>
      <li class="">
        <h3><a href="">Link</a></h3>
      </li>
      <li class="">
        <h3><a href="">Link</a></h3>
      </li>
      <li class="active">
        <h3><a href="">Link</a></h3>
      </li>
    </ul>
  </div>
  <!- - sidebar - ->
  <div class="sidebar-content col-sm-9">
    <ul>
      <li class="active">
        <h2 class="underline">Link</h2>
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rerum nostrum assumenda sequi praesentium aperiam. Accusamus omnis velit quos sint quas corporis inventore, facilis laborum pariatur explicabo maxime voluptas at aliquid!</p>
      </li>
      <li class="">
        <h2 class="underline">Link</h2>
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rerum nostrum assumenda sequi praesentium aperiam. Accusamus omnis velit quos sint quas corporis inventore, facilis laborum pariatur explicabo maxime voluptas at aliquid!</p>
      </li>
      <li class="">
        <h2 class="underline">Link</h2>
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rerum nostrum assumenda sequi praesentium aperiam. Accusamus omnis velit quos sint quas corporis inventore, facilis laborum pariatur explicabo maxime voluptas at aliquid!</p>
      </li>
      <li class="">
        <h2 class="underline">Link</h2>
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rerum nostrum assumenda sequi praesentium aperiam. Accusamus omnis velit quos sint quas corporis inventore, facilis laborum pariatur explicabo maxime voluptas at aliquid!</p>
      </li>
    </ul>
  </div>
  <!- - sidebar-content - ->
</div>
<!- - row - ->

Also, here is my CSS code:

.sidebar {
background: #eee;
height: 100%;
padding-top: 100px !important;
}

.sidebar-content ul li {
display: none;
}

.sidebar-content ul li.active {
display: block;
}

.sidebar-content {
position: relative;
right: 0;
padding: 100px;
}

If anyone knows how to make the div relatively positioned while maintaining it at full height or has suggestions for a better approach in creating a sidebar, please advise.

Fiddle Link: https://jsfiddle.net/3Lapzoyf/3/

Answer №1

Solution:

To create a sidebar with a height of 100% of the viewport height, set the height to 100vh. Ensure that your rows are wrapped inside a .container or .container-fluid when working with Twitter Bootstrap.

HTML:

<div class="container">
    <div class="row">
      <div class="sidebar col-sm-3">
        <ul>
          <li class="active">
            <h3><a href="">Link</a></h3>
          </li>
          ...
          ...
        </ul>
      </div><!-- sidebar -->
      <div class="sidebar-content col-sm-9">
        <ul>
         ...
         ... 
        </ul>
      </div><!-- sidebar-content -->
  </div><!-- row -->
</div>

CSS:

.sidebar {
  background: #eee;
  height: 100vh;
  padding-top: 100px;  
}

.sidebar-content ul li {
  display: none;
}

.sidebar-content ul li.active {
  display: block;
}

.sidebar-content {
  padding: 100px;
  position: relative;
  right: 0;
}

Fiddle: https://jsfiddle.net/3Lapzoyf/4/

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

PHP MySQL outputting data in a dropdown menu format

Struggling to extract data from a database and display it as a dropdown list. I am fetching the foreign key, its unique code, and its name/title to be displayed in a dropdown list for input into a new table. $sql = "SELECT quali_code, title FROM ...

Adding a dynamic index from ngFor to an HTML attribute value can be accomplished by incorporating the current

I am using ngFor and I am trying to make an attribute inside the loop change its value by adding the ngFor index. This means that each div created within ngFor will have a unique attribute value. Source: <div class="class1" *ngFor="let item of items; l ...

How can I resolve the vertical adjustment issue of Bootstrap 5 input group on mobile devices?

My current issue involves using Bootstrap 5.2.3 to create an input group that displays a set of spans with the ".input-group-text" class alongside inputs with the ".form-control" class. While this setup works well on a computer screen, it does not adjust c ...

Configure UL element as a dropdown on mobile devices and expand it to full width on desktop screens

Circumstances This HTML code is intended to create a horizontal <ul> element that spans the entire width of the <div class="list__wrapper"> container on desktop screens with a minimum width of 1024px. However, for mobile devices with a maximum ...

Can Fields Be Concealed Based on the User's Choice?

Can options be dynamically hidden in a select field based on user input using Javascript or jQuery? I am working on a complex and lengthy form and I'm trying to minimize the number of HTML elements to avoid confusion with conditional logic. The user ...

What's the deal with $routeProvider in angularJS?

I'm having some trouble with my simple web app that I'm trying to update using route provider. Everything works fine when I click on the list items on the page, but when I refresh the page, I get a 404 error. It seems like it's trying to acc ...

What could be causing the issue with my php login page not functioning properly?

When I try to log in, the system does not verify whether the user login is successful or not. Instead, it redirects me back to the login page after entering my username and password. Also, the header location function doesn't seem to be working proper ...

Concealing my menu with overflow-x: hidden on the body is not an option

Despite setting overflow-x: hidden on the body element, I'm still experiencing horizontal scrolling and can't seem to find a solution. I've searched online for solutions without success. That's why I'm reaching out here in hopes o ...

Utilizing JSON for HTML conversion in Codeigniter

public function getCrew(){ $search = $this->input->post('name'); if($this->input->post('ajax') && (!empty($search))){ $result = $this->model->getNames($search); foreach($result as $r){ ...

The footer is failing to appear in its correct position on the homepage of the Rails application

My footer looks great throughout my Rails app except for the Home page. Here is the content of my application.html file: <!DOCTYPE html> <html> <head> <title><%= yield(:title) || "Wagon Rails" %></title> <meta n ...

Utilize jQuery Function on Identical Class of <ul> Elements

I have integrated a listview control in my ASPX page. The data is being fetched from the database and displayed in the listview. I have also utilized jQuery script to implement the .fadein() and .fadeout() effects on the listview elements. However, when I ...

What are the steps to creating the arrow symbol shown in the image provided?

I've come across a design that includes a text arrow that looks like this: https://i.sstatic.net/lzBAE.png Is there a way to create that arrow design? Using the standard > doesn't seem quite right: https://i.sstatic.net/7b6T6.png ...

Is there a way to stop text from being selected when double clicking?

#btnLeft{ width:40px; padding:2px 5px 2px 5px; background-color: #20a0a0; border: thin solid #099; border-radius:7px; text-align:center; font-family:"Futura Md BT"; font-size:large; color:#FFF; } This particular code sn ...

Applying the .active class to a button which reveals the corresponding div

I've been working on a menu that functions to open and hide divs within a single page. My objective is to have the (.active) class applied to the currently selected menu item only when its connected div is open. When the div is closed or another menu ...

Troubleshooting the Issue of Table Append not Functioning in Live Environment

I'm currently in the process of developing a website using Bootstrap, and I'm facing an issue where one of the tables gets cleared out and updated with new data when a button is clicked. This functionality works perfectly fine during testing on V ...

Ways to prevent browser scrolling on smartphones and tablets

Having a simple HTML file with an iframe embedded, I have been attempting to prevent my browser from scrolling in both documents. However, this solution works intermittently and does not provide consistent results. I have tried applying various event list ...

Troubleshooting the malfunctioning of the Bootstrap slide animation

I've been attempting to implement scroll animation on a div, but for some reason, it's not working as intended. I must have made a mistake somewhere, but I can't figure out where. Any help in resolving this issue would be greatly appreciated ...

Manually adjusting the aria-expanded attribute to "true" does not result in opening a new tab

After a certain condition is met, I want to open another tab. Below is my bootstrap navbar code along with the jQuery script. <ul class="nav navbar-default nav-justified" role="tablist" id="navbar"> <li role="presentation" class="active"><a ...

Steps for making a toggle button with Bootstrap

Initially, I developed a web application using HTML, CSS, and JavaScript. Later on, I was requested to recreate it using Bootstrap as well. While I managed to complete the task successfully, I encountered an issue where toggle buttons in the web app revert ...

Styling for elements containing any class or id in Css

Struggling with applying different styles to two image tags within one div tag? I attempted to use CSS to target the images individually, but it didn't work. Can someone help me correct my CSS code? This is how I tried to apply the CSS: div img { pa ...