Implementation of CSS equal division of parent container (perfect thirds)

Implementation of CSS equal division of parent container (perfect thirds)

The width of the parent container is fixed. In order to achieve that the child elements perfectly divide the parent width in equal proportion, what are the ways to achieve it?

HTML part of the code:

Method 1: Floating layout + percentage

(Float the sub-elements to the left one by one, and set the width percentage of each sub-element according to the number of sub-elements)

Method 2: Inline-block + percentage

Method 3: Parent element display:table + child element display:table-cell

Method 4: css3 display:flex; (flex layout)

Method 5: Grid system (bootstrap)

Add the class attribute class=“col-md-3” to the child element

The above five methods can all achieve the equal division of the parent element container into three equal parts, but the first two methods based on percentages cannot achieve perfect division into three equal parts, because the percentage is an inaccurate estimate, and if the child element has a border, it is difficult to divide it equally.

The last three methods are preferred

This is the end of this article about the implementation of CSS proportional division of parent containers (perfect thirds). For more relevant CSS proportional division of parent containers content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

<<:  TypeScript decorator definition

>>:  Web realizes the code of popping up the window of uploading files by clicking the picture

Recommend

Example of how to quickly build a LEMP environment with Docker

LEMP (Linux + Nginx + MySQL + PHP) is basically a...

Version numbers in css and js links in HTML (refresh cache)

background Search the keyword .htaccess cache in ...

Alibaba Cloud domain name and IP binding steps and methods

1 Enter the Alibaba Cloud console, find the domai...

An article explains Tomcat's class loading mechanism

Table of contents - Preface - - JVM Class Loader ...

Building .NET Core 2.0 + Nginx + Supervisor environment under Centos7 system

1. Introduction to Linux .NET Core Microsoft has ...

JavaScript to achieve a simple carousel effect

What is a carousel? Carousel: In a module or wind...

WeChat applet + ECharts to achieve dynamic refresh process record

Preface Recently I encountered a requirement, whi...

Using HTML to implement a voting website cheating scheme that restricts IP

This is a cheating scheme for voting websites wit...

HTML head structure

The following introduces the commonly used head s...

Ant Design Blazor component library's routing reuse multi-tab function

Recently, there has been a growing demand for imp...