Home > Web Front-end > CSS Tutorial > Can Bootstrap Create Fixed and Fluid Column Layouts?

Can Bootstrap Create Fixed and Fluid Column Layouts?

Barbara Streisand
Release: 2024-11-16 03:23:02
Original
439 people have browsed it

Can Bootstrap Create Fixed and Fluid Column Layouts?

How to Create a 2 Column Fluid-Fixed Layout with Twitter Bootstrap

Question:

Can you implement a fixed-fluid two-column layout using Twitter Bootstrap?

Solution:

Yes, it is possible with Bootstrap 2.0 onwards but requires some modification to the standard class implementation. Here's a solution using HTML and CSS:

HTML:

<div class="container-fluid fill">
    <div class="row-fluid">
        <div class="fixed">  <!-- Fixed width div -->
            ...
        </div>
        <div class="hero-unit filler">  <!-- Filler div without spanX class -->
            ...
        </div>
    </div>
</div>
Copy after login

CSS:

/* Fixed-fluid layout */
.fixed {
    width: 150px;
    float: left;
}

.fixed + div {
    margin-left: 150px;
    overflow: hidden;
}

/* Equal height columns (optional) */
html, body {
    height: 100%;
}

.fill { 
    min-height: 100%;
    position: relative;
}

.filler:after{
    background-color:inherit;
    bottom: 0;
    content: &quot;&quot;;
    height: auto;
    min-height: 100%;
    left: 0;
    margin:inherit;
    right: 0;
    position: absolute;
    top: 0;
    width: inherit;
    z-index: -1;  
}
Copy after login

Explanation:

  • Add a .fill class to the outermost div to ensure a minimum height of 100%.
  • Float the fixed width column to the left.
  • Use pseudo-element in .filler to provide a visual illusion of equal height columns.
  • Position the filler div relatively to the .fill div using position: relative.

The above is the detailed content of Can Bootstrap Create Fixed and Fluid Column Layouts?. For more information, please follow other related articles on the PHP Chinese website!

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