Home Web Front-end H5 Tutorial Introduction to the style of html5 table tag (attached is an example of html5 table css centering)

Introduction to the style of html5 table tag (attached is an example of html5 table css centering)

Aug 21, 2018 pm 02:19 PM
html5 table

HTML table tag style introduction (attached is an example of html5 table css centering). This article mainly tells you the definition of html5 table tag and the introduction of various styles.

HTML 5 <table> tag definition and usage:

<table> tag can define a table. Inside the <table> tag, you can place table titles, table rows, table columns, table cells, and other tables.

html Standard attributes of table tags:

class, contenteditable, contextmenu, dir, draggable, id, irrelevant,

lang, ref, registrationmark , tabindex, template, title

html table style example introduction:

&lt;table border=&quot;1&quot;&gt;
    &lt;tr&gt;
            &lt;td width=&quot;95&quot; align=&quot;right&quot; valign=&quot;top&quot; nowrap=&quot;nowrap&quot;&gt;&lt;strong&gt;处理意见:&lt;/strong&gt;&lt;/td&gt;    
            &lt;td id=&quot;fnote&quot;  width=&quot;300px&quot; colspan=&quot;8&quot;&gt; &lt;/td&gt;                     
    &lt;/tr&gt;
    &lt;tr&gt;
            &lt;td&gt;&lt;a href=&quot;#&quot; onclick=&quot;showad()&quot;&gt;审批记录&lt;/a&gt;&lt;/td&gt;
    &lt;/tr&gt;                
&lt;/table&gt;
Copy after login

width: the width of the column

align: the horizontal arrangement of cell content :right left center

valign: vertical arrangement of cell content: top bottom middle baseline

colspan: the number of columns that the cell can span

rowspan: the number of columns that the cell can span Number of rows

rowspan=3 tr

nowrap: Specifies whether the content in the cell should be folded


table Unique style attributes:

1. Border merge

Attribute: border-collapse

Value:

1. separate

Default value, separate border mode

2.collapse

Border merge mode

2.Border margin

1. Function

Set the distance between adjacent cell borders (similar to cellspacing)

2. Attribute

border-spacing

Value:

1. Take 1 value

means the horizontal and vertical spacing are equal

2. Take 2 values ​​

The horizontal spacing represented by one value

The vertical spacing represented by the second value

Separate the two values ​​with a space

3. Requirements

border-collapse must be separate

Must be valid in separate border mode

3. Title position

<caption></caption> ;

Function: Change the title position from the default position to below the table

Attribute: caption-side

Value:

1. top

Default

2. Bottom

The title is under the table

Use div to center the table in css:

I saw that using display: table-cell can render a div into a cell, and the content in the table td is all centered. Then I thought of a div containing a div, and the div inside is vertically centered. I guess it can be done. Use:

Set the outer div to display:table-cell, then the inner div will be automatically centered vertically.

After testing, I found that the inner div is not centered, then use vertical-align to center it. Because:

Only if one element belongs to inline or inline-block (table-cell can also be understood as inline-block level) level, the vertical-align attribute on it will work.

For example, pictures, buttons, single check boxes, single-line/multi-line text boxes and other HTML controls. Only these elements will have an effect on the vertical-align attribute by default.

Now you can use vertical-align:middle in table-cell to center the content vertically. What if I want to achieve horizontal centering? text-algin: center, suitable for inline elements, then I just need to set the div inside to line-block

Code verification:

&lt;style&gt;
        .table {
            display: table-cell;
            vertical-align: middle;
            text-align: center;
        }
        .like {
            display: inline-block;
            width:100px;
            height:50px;
            border:2px solid black;
        }
    &lt;/style&gt;
&lt;div class=&quot;table&quot; style=&quot;width:300px;height: 300px;background-color: #13c4a5&quot;&gt;
    &lt;div class=&quot;like&quot;&gt;
    &lt;/div&gt;
&lt;/div&gt;
Copy after login

[Related recommendations]

html What does the strong tag mean? Introduction to the specific usage of the strong tag in html

html5 How to use the audio tag? HTML5 automatic playback implementation code example

The above is the detailed content of Introduction to the style of html5 table tag (attached is an example of html5 table css centering). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

Nested Table in HTML

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Table Border in HTML

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

HTML margin-left

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

HTML Table Layout

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Moving Text in HTML

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

HTML Ordered List

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

HTML onclick Button

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

HTML Input Placeholder

See all articles