Example code for implementing equal width layout in multiple ways using CSS

Example code for implementing equal width layout in multiple ways using CSS

The equal-width layout described in this article uses pure CSS to achieve the effect of making each element have the same width without manually setting the element width.

1. Use table-cell to implement (compatible with ie8)

<style>
    body,div{
        margin: 0;
        padding: 0;
    }
    .table-layout{
        display: table;/*The parent element must be set to table*/
        table-layout: fixed;/*This attribute must be present, otherwise the effect will not be achieved*/
        width: 50%;
        margin: 20px auto;
    }
    .table-cell-layout{
        display: table-cell;/*The child element must be set to table-cell*/
        height: 40px;
        border: 1px solid #666;
        border-left: none;
    }
    .table-cell-layout:first-child{
        border-left: 1px solid #666;
    }
</style>

<body>
    <ul class="table-layout">
        <li class="table-cell-layout">li1</li>
        <li class="table-cell-layout">li2</li>
        <li class="table-cell-layout">li3</li>
        <li class="table-cell-layout">li4</li>
        <li class="table-cell-layout">li5</li>
    </ul>
</body>

2. Use flex layout to achieve

<style>
    body,div{
        margin: 0;
        padding: 0;
    }
    .flex-layout{
        display: flex;
        width: 50%;
        margin: 20px auto;
    }
    .flex-item{
        flex: 1;
        height: 40px;
        border: 1px solid #666;
        border-left: none;
    }
    .flex-item:first-child{
        border-left: 1px solid #666;
    }
</style>

<body>
    <ul class="flex-layout">
        <li class="flex-item">li1</li>
        <li class="flex-item">li2</li>
        <li class="flex-item">li3</li>
        <li class="flex-item">li4</li>
        <li class="flex-item">li5</li>
    </ul>
</body>

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

<<:  How to copy MySQL table

>>:  Getting Started Guide to Converting Vue to React

Recommend

Vue implements Tab tab switching

This article example shares the specific code of ...

Implementation of two basic images for Docker deployment of Go

1. golang:latest base image mkdir gotest touch ma...

mysql trigger creation and usage examples

Table of contents What is a trigger Create a trig...

Explaining immutable values ​​in React

Table of contents What are immutable values? Why ...

Detailed explanation of the binlog log analysis tool for monitoring MySQL: Canal

Canal is an open source project under Alibaba, de...

CSS isolation issue in Blazor

1. Environment VS 2019 16.9.0 Preview 1.0 .NET SD...

How to use mysqldump to backup MySQL data

1. Introduction to mysqldump mysqldump is a logic...

Detailed explanation of two points to note in vue3: setup

Table of contents In vue2 In vue3 Notes on setup ...

Use overflow: hidden to disable page scrollbars

Copy code The code is as follows: html { overflow...

Clean XHTML syntax

Writing XHTML demands a clean HTML syntax. Writing...

Detailed explanation of the reasons why MySQL connections are hung

Table of contents 1. Background Architecture Prob...

Detailed explanation of the difference between uniapp and vue

Table of contents 1. Simple page example 2.uni-ap...

Vue3 (Part 2) Integrating Ant Design Vue

Table of contents 1. Integrate Ant Design Vue 2. ...

Summary of Linux system user management commands

User and Group Management 1. Basic concepts of us...