Home > Web Front-end > CSS Tutorial > How to Keep the Sidebar Fixed on Scroll in Fluid Bootstrap 2.0?

How to Keep the Sidebar Fixed on Scroll in Fluid Bootstrap 2.0?

Linda Hamilton
Release: 2024-11-08 22:35:02
Original
306 people have browsed it

How to Keep the Sidebar Fixed on Scroll in Fluid Bootstrap 2.0?

Keeping the Sidebar Fixed on Scroll in Fluid Bootstrap 2.0

For fluid layout, it's possible to fix the sidebar navigation on scroll by implementing a custom class.

Custom CSS

Create a .sidebar-nav-fixed class to control the sidebar's fixed position and add .row-fluid > .span-fixed-sidebar to the content container to offset the sidebar's margin. Here's the CSS:

.sidebar-nav-fixed {
    padding: 9px 0;
    position:fixed;
    left:20px;
    top:60px;
    width:250px;
}

.row-fluid > .span-fixed-sidebar {
    margin-left: 290px;
}
Copy after login

HTML Structure

Use the following HTML structure to implement the fixed sidebar:

<div class="container-fluid">
  <div class="row-fluid">
    <div class="span3">
      <div class="well sidebar-nav sidebar-nav-fixed">
        ...
      </div>
    </div>
    <div class="span9">
      ...
    </div>
  </div>
</div>
Copy after login

Advanced Configuration

For more flexibility, use CSS media queries to adjust the sidebar's position based on screen size. Here's an example:

@media (max-width: 767px) {
    .sidebar-nav-fixed {
        width:auto;
    }
}

@media (max-width: 979px) {
    .sidebar-nav-fixed {
        position:static;
        width: auto;
    }
}
Copy after login

This configuration keeps the sidebar fixed until the screen size drops for small screens or mobile view.

The above is the detailed content of How to Keep the Sidebar Fixed on Scroll in Fluid Bootstrap 2.0?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template