Home > Web Front-end > CSS Tutorial > How to Create Full-Screen Two-Column Layouts with Different Background Colors Using Bootstrap?

How to Create Full-Screen Two-Column Layouts with Different Background Colors Using Bootstrap?

Barbara Streisand
Release: 2024-12-01 02:47:10
Original
178 people have browsed it

How to Create Full-Screen Two-Column Layouts with Different Background Colors Using Bootstrap?

How to Create Two Columns with Different Background Colors that Span to the Screen Edge

Problem:

You wish to create two columns on a webpage, each with a distinct background color, extending to the screen's edges. However, the content of the columns should stay within the fixed width of the Bootstrap grid system.

Solution:

Using Bootstrap 5 Beta:

The concept remains similar in Bootstrap 5:

  • Use a pseudo-element with an absolute position on the column(s) to create the illusion of a container within a container-fluid.

Example for Bootstrap 5 Beta:

<div class="container-fluid">
    <div class="row">
        <div class="col-6 bg-info">
            <div class="row justify-content-end">
                <div class="col-9"> ... </div>
            </div>
        </div>
        <div class="col-6 bg-danger">
            <div class="row justify-content-start">
                <div class="col-9"> ... </div>
            </div>
        </div>
    </div>
</div>
Copy after login
Copy after login

Alternatively for Bootstrap 5:

  • Utilize container-fluid and insert smaller grid columns within the outer columns, each with its background color.

Using Bootstrap 4:

The concept is akin to Bootstrap 5, but without the "-xs-" infix.

Example for Bootstrap 4:

<div class="container-fluid">
    <div class="row">
        <div class="col-6 bg-info">
            <div class="row justify-content-end">
                <div class="col-9"> ... </div>
            </div>
        </div>
        <div class="col-6 bg-danger">
            <div class="row justify-content-start">
                <div class="col-9"> ... </div>
            </div>
        </div>
    </div>
</div>
Copy after login
Copy after login

Using Bootstrap 3:

Wrap a second container within another wrapper DIV:

<div class="container">
Copy after login

Utilizing a Pseudo-Element in Bootstrap 3:

.right:before {
    right: -999em;
    background: rebeccapurple;
    content: '';
    display: block;
    position: absolute;
    width: 999em;
    top: 0;
    bottom: 0;
}
Copy after login

The above is the detailed content of How to Create Full-Screen Two-Column Layouts with Different Background Colors Using 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