Home > Web Front-end > CSS Tutorial > How to Create a Fixed-Fluid 2-Column Layout with Twitter Bootstrap?

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

Barbara Streisand
Release: 2024-11-16 11:20:03
Original
274 people have browsed it

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

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

Background

Creating a 2-column layout with one fixed-width column and one fluid-width column is a common design pattern. Earlier versions of Twitter Bootstrap allowed this using the .container-fluid class, but this is no longer supported in Bootstrap 2.0 and later.

Solution

To address this, we can employ a combination of CSS and slightly modified HTML code:

HTML

<div class="container-fluid fill">
    <div class="row-fluid">
        <div class="fixed">...Fixed Column...</div>
        <div class="hero-unit filler">...Fluid Column...</div>
    </div>
</div>
Copy after login

CSS

/* Fixed-Fluid Layout CSS */

.fixed {
    width: 150px;  /* Fixed width for fixed column */
    float: left;
}

.fixed + div {
    margin-left: 150px;  /* Match fixed width from .fixed class */
    overflow: hidden;
}

/* Content Height Equalization CSS (optional) */

html, body {
    height: 100%;
}

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

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

Notes

  • Adjust .fixed width to your desired fixed column size.
  • To display the fluid column on the left, replace right: 0 with left: 0 in the .filler CSS.
  • The additional CSS is optional but ensures that the fixed and fluid columns are the same height.

The above is the detailed content of How to Create a Fixed-Fluid 2-Column Layout with Twitter Bootstrap?. 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