CSS3 flexible box flex to achieve three-column layout

CSS3 flexible box flex to achieve three-column layout

As the title says: The height is known, the width of the left and right columns is 300px, and the middle is adaptive:

The elastic box itself is side by side, we just need to set the width.

Use a container to wrap the three columns, set the display property of the container to flex, set the width of the left and right columns to 300px, and set flex:1 for the middle column. Here 1 represents the width ratio. The specific value depends on the flex value of other boxes. Since the width of other boxes is fixed here, the middle column will be automatically filled:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Three-column layout</title>
</head>
<style type="text/css">
    html*{
        margin: 0;
        padding: 0;
    }
    .container{
        display: flex;
    }
    .left{
        background-color: aqua;
        width: 300px;
        height: 100px;
    }
    .center{
        height: 100px;
        flex: 1;
        background: #f296ff;
    }
    .right{
        height: 100px;
        background-color: #6ee28d;
        width: 300px;
    }
</style>
<body>
<!-- Given the height, write a three-column layout with 300px width on the left and right and adaptive width in the middle -->
<div class="container">
    <div class="left"></div>
    <div class="center"></div>
    <div class="right"></div>
</div>
</body>


</html>

The effect is as shown below:

This concludes this article about how to use CSS3 flexible box flex to implement a three-column layout. For more information about CSS3 flex three-column layout, please search 123WORDPRESS.COM’s previous articles or continue browsing the following related articles. I hope you will support 123WORDPRESS.COM in the future!

<<:  How to use html css to control div or table to be fixed in a specified position

>>:  Install JDK1.8 in Linux environment

Recommend

Basic usage examples of Vue named slots

Preface Named slots are bound to elements using t...

js object to achieve data paging effect

This article example shares the specific code of ...

How to add file prefixes in batches in Linux

You need to add "gt_" in front of the f...

Detailed explanation of how to install MySQL on Alibaba Cloud

As a lightweight open source database, MySQL is w...

Install and build a server environment of PHP+Apache+MySQL on CentOS

Yum (full name Yellow dog Updater, Modified) is a...

Causes and solutions for slow MySQL query speed and poor performance

1. What affects database query speed? 1.1 Four fa...

Windows 2019 Activation Tutorial (Office2019)

A few days ago, I found that the official version...

Method for realizing Internet interconnection by VMware virtual machine bridging

After installing VMware and creating a new virtua...

Vue3 realizes the image magnifying glass effect

This article example shares the specific code of ...

Sample code for implementing 3D rotation effect using pure CSS

Mainly use the preserve-3d and perspective proper...

MySQL Null can cause 5 problems (all fatal)

Table of contents 1. Count data is lost Solution ...

DOCTYPE Document Type Declaration (Must-Read for Web Page Lovers)

DOCTYPE DECLARATION At the top of every page you w...