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

Detailed steps to install VMware Tools from scratch (graphic tutorial)

VMware Tools is a tool that comes with VMware vir...

Detailed introduction to CSS font, text, and list properties

1. Font properties color, specifies the color of ...

Sample code using scss in uni-app

Pitfalls encountered I spent the whole afternoon ...

7 ways to vertically center elements with CSS

【1】Know the width and height of the centered elem...

MySQL 5.7 installation and configuration tutorial under CentOS7 (YUM)

Installation environment: CentOS7 64-bit, MySQL5....

Vue Basics Listener Detailed Explanation

Table of contents What is a listener in vue Usage...

Introduction to MySQL Connection Control Plugin

Table of contents 1. Introduction to the connecti...

Example code for using text-align and margin: 0 auto to center in CSS

Use text-align, margin: 0 auto to center in CSS W...

Notes on Using Textarea

Why mention textarea specifically? Because the tex...

This article takes you into the world of js data types and data structures

Table of contents 1. What is dynamic typing? 2. D...

How to change the encoding to utf-8 in mysql version 5.7 under windows

Preface I just started learning MySQL and downloa...

Vue implements a movable floating button

This article example shares the specific code of ...

Apache Log4j2 reports a nuclear-level vulnerability and a quick fix

Apache Log4j2 reported a nuclear-level vulnerabil...