Home >Web Front-end >CSS Tutorial >How do I create a five-column layout in Bootstrap?
In this question, the user is attempting to create a five-column layout using Bootstrap but is experiencing issues. To resolve this, we'll explore different approaches using various Bootstrap classes and grid system.
The initial code provided by the user included a container class with a row and multiple nested columns. To achieve a true five-column layout with equal widths, the auto-layout grid approach used in Bootstrap 4 offers a simpler solution.
By using the container-fluid class instead of container, you can create an auto-layout grid that automatically distributes equal widths to child elements. The nested div elements within the row will then fill the container's width equally.
<div class="container-fluid"> <div class="row"> <div class="col">1</div> <div class="col">2</div> <div class="col">3</div> <div class="col">4</div> <div class="col">5</div> </div> </div>
As of Bootstrap 4.4, a new class called row-cols-5 was introduced. This class simplifies the creation of a five-column layout within a row.
<div class="container"> <div class="row row-cols-5"> <div class="col"> X </div> <div class="col"> X </div> <div class="col"> X </div> <div class="col"> X </div> <div class="col"> X </div> <div class="col"> X </div> </div> </div>
By utilizing these approaches, you can create a flexible and responsive five-column layout using Bootstrap. Remember to adjust the classes based on the specific Bootstrap version you are using.
The above is the detailed content of How do I create a five-column layout in Bootstrap?. For more information, please follow other related articles on the PHP Chinese website!