Solution to the problem of adaptive height and width of css display table

Solution to the problem of adaptive height and width of css display table

Definition and Usage

The display property specifies the type of box an element should generate.

illustrate

This attribute is used to define the type of display frame that the element generates when building a layout. For document types such as HTML, using display can be dangerous if not careful, because it can violate the display hierarchy defined in HTML. With XML, since XML has no such hierarchy built into it, all display is absolutely necessary.
Possible values

value describe
none This element will not be displayed.
block This element will be displayed as a block level element with line breaks before and after the element.
inline default. This element will be displayed as an inline element, with no line breaks before or after the element.
inline-block Inline-block element. (Value added in CSS2.1)
list-item This element is displayed as a list.
run-in This element is displayed as a block-level element or an inline element, depending on the context.
compact There is a value called compact in CSS, but it was removed from CSS 2.1 due to lack of widespread support.
marker CSS has value markers, but they have been removed from CSS2.1 due to lack of widespread support.
table This element will be displayed as a block-level table similar to a table, with line breaks before and after the table.
inline-table This element will be displayed as an inline table similar to a table, with no line breaks before and after the table.
table-row-group This element will be displayed similar to tbody as a group of one or more rows.
table-header-group This element will be displayed similar to thead as a grouping of one or more rows.
table-footer-group This element will be displayed similar to tfoot as a grouping of one or more rows.
table-row This element will be displayed as a table row similar to tr.
table-column-group This element will be displayed as a group of one or more columns similar to colgroup.
table-column This element will be displayed as a cell column similar to col
table-cell This element will be displayed as a table cell similar to td and th
table-caption This element will be displayed as a table title similar to caption
inherit Specifies that the value of the display property should be inherited from the parent element.

Elements with display: table-cell set:

  • Sensitive to width and height
  • No response to margin value
  • Responsive padding properties
  • When the content overflows, the parent element will be expanded automatically

The effect picture achieved above is that the left avatar part uses the float left floating attribute, and the right side uses display: table-cell to achieve a two-column adaptive layout.

display: table; The outer layer defines the width and height, and the content inside adapts to the width and height. If the child element is a div, the width of each column is not equally divided. Therefore, it is recommended to use li tags for child elements

.css-table {
      display: table;
      height: 2rem;
      width: 5rem;
  }
  .css-table-bg {
      display: table-cell;
      vertical-align: middle;
      text-align: center;
      background-color: coral;
  }
  .css-table li {
      display: table-cell;
      vertical-align: middle;
      text-align: center;
      background-color:darkkhaki;
  }

    <div class="css-table">
     <div class="css-table-bg">1</div>
        <div class="css-table-bg">2</div>
        <div class="css-table-bg">3</div>
    </div>
    <div class="css-table">
        <ul> 
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Clients</a></li>
        </ul>
    </div>

This is the end of this article about how to solve the problem of adaptive height and width of CSS display table. For more relevant content about adaptive CSS display table, please search previous articles on 123WORDPRESS.COM or continue to browse the related articles below. We hope that you will support 123WORDPRESS.COM in the future!

<<:  Brief introduction and usage of Table and div

>>:  How to directly reference vue and element-ui in html

Recommend

How to check where the metadata lock is blocked in MySQL

How to check where the metadata lock is blocked i...

How to use CSS counters to beautify ordered lists of numbers

In web design, it is very important to use an org...

How to install MySQL 8.0 database on M1 chip (picture and text)

1. Download First of all, I would like to recomme...

Summary of MySQL commonly used type conversion functions (recommended)

1. Concat function. Commonly used connection stri...

A simple tutorial on how to use the mysql log system

Table of contents Preface 1. Error log 2. Binary ...

Docker installs ClickHouse and initializes data testing

Clickhouse Introduction ClickHouse is a column-or...

Pure CSS code to achieve drag effect

Table of contents 1. Drag effect example 2. CSS I...

The ultimate solution for writing bash scripts with nodejs

Table of contents Preface zx library $`command` c...

Do not start CSS pseudo-class names with numbers

When newbies develop div+css, they need to name t...

In-depth understanding of the vertical-align property and baseline issues in CSS

vertical-align attribute is mainly used to change...

CentOS uses local yum source to build LAMP environment graphic tutorial

This article describes how to use the local yum s...

Solution to the problem of slow docker pull image speed

Currently, Docker has an official mirror for Chin...

Linux uses shell scripts to regularly delete historical log files

1. Tools directory file structure [root@www tools...

Implementing simple chat room dialogue based on websocket

This article shares the specific code for impleme...

How to implement load balancing in MySQL

Preface MySQL is a high-speed, high-performance, ...