Home > Web Front-end > HTML Tutorial > What are the HTML table attributes? Summary of 10 basic attributes of HTML tables

What are the HTML table attributes? Summary of 10 basic attributes of HTML tables

不言
Release: 2018-07-27 14:45:19
Original
30891 people have browsed it

HTML table attribute settings are widely used in HTML web pages and are also crucial. Therefore, in this next article, I will share with you a summary of the 10 basic attributes of HTML tables. Let’s look at them below. Take a look at the introduction and specific codes of these 10 table attributes.

1. HTML table attribute


is used to define HTML tables. It has the local attribute border to represent the border. The value of the border attribute must be 1 or the empty string (""). This attribute does not control the style of the border, but is controlled by CSS

table elements can have tr, th, td, thead, tbody, tfoot, colgroup elements

table tags The basic attributes are as follows:

border: The possible values ​​are 1 and 0, 1 means there is a border, and 0 means there is no border.

bordercolor: You can set the color of the border, the value is the color value.

bgcolor: Set the background color of the table

background: Set the background image

2, html tr attribute

Used to define a row of the table. Since HTML tables are row-oriented, each row must be represented separately.

tr elements can be used within table, thead, tbody and tfoot elements.

tr elements can contain one or more tds. Or th element

its align, bgcolor and other attributes are obsolete. If you want to set attributes, please use CSS settings

3, HTML td attribute

Used to define the header of the table and the wrapper of the header. You can define one or more rows, which are column labels of the table element

Without thead element, all tr ​​are assumed to belong to the main body of the table

6, HTML tbody attribute

Used to define the body of the table

7, HTML tfoot attribute

Used to define the footer of the marked table

Note:

##, tags must have the tag inside

and tags are placed in

Used to define table cells, which can be used with colspan, rowspan, and headers local attributes

(1) colspan: column span, this attribute specifies the number of columns that the cell can span. The value of the attribute must be an integer

 (2)rowspan: row span, this attribute specifies the number of rows that the cell can span, the value of this attribute must be an integer

 (3)headers : The value of this attribute is the ID attribute value of one or more cells, associates the cells with column headers, and can be used with screen readers

Note:Each table must contain The above three elements

4. The html th attribute

is used to define the title cell, allowing us to effectively distinguish data and its description

It has the same local attributes as the

element. The difference between the two is as follows:

represents the header tag, usually located in the first row or column. Moreover, the text in will be bolded by default, but will not.

is a data mark, indicating the specific data of the cell

The valign attribute can be set to th and td, and can take the value Top or Bottom.

callpadding: the distance between the content and the cell border

cellspacing: preventing the text from exceeding the border

If you want to make the cell cross rows or columns, use the attributes colspan and rowspan .

5. HTML thead attribute

Whichever position within the label will be determined to be the head and bottom of the table respectively.

can appear before or after or .

Before html5, the
element must appear before the element. In html5, the element can be placed on the or the last element. Behind


8, html colgroup attribute

is used to define table column groups, which can be used to style Applied to a certain column, of course you can also use the col element

mentioned below. The
with the local attribute span indicates the number of columns that the column group should span. The default is one column, that is, setting the style for one column of the table

 
can contain one or more elements

9, HTML col attribute

Used to represent a single column of the table, it is recommended to use to wrap the element instead of to directly set the span attribute to define the group

 
It also has the local attribute span

.
is placed inside the element of . The instance of represents a column in the group. Use this tag to apply styles to a group of columns and a single column of the group

10, html caption attribute

Used to define the title of the table. Each table can only contain one

element

11. Example code:

<body>
    <table border="1" bordercolor="red" bgcolor="#ff4646">
        <caption>表格示例</caption>
        <tr align="center">
            <th>标题1</th>
            <th>标题2</th>
            <th>标题3</th>
        </tr>
        <tr>
            <td align="left">左</td>
            <td align="center">中</td>
            <td align="right">右</td>
        </tr>
        <tr>
            <td valign="top">top</td>
            <td>center</td>
            <td valign="bottom">bottom</td>
        </tr>
    </table>
</body>
Copy after login

Run result:

What are the HTML table attributes? Summary of 10 basic attributes of HTML tables

##Cell across rows

<table border="1" bordercolor="#1f1fff">
       <caption>单元格的跨行</caption>
       <tr>
           <th>姓名</th>
           <th colspan="2">电话</th>
       </tr>
       <tr>
           <td>php中文网</td>
           <td>123456   654321</td>
       </tr>
   </table>
Copy after login

Run result:

What are the HTML table attributes? Summary of 10 basic attributes of HTML tables

Cells across columns

<table border="1">
     <caption>单元格跨列</caption>
     <tr>
         <th>姓名</th>
         <th>电话</th>
     </tr>
     <tr>
         <td rowspan="2">php中文网</td>
         <td>123456</td>
     </tr>
     <tr>
         
         <td>654231</td>
     </tr>
 </table>
Copy after login
Run results:

What are the HTML table attributes? Summary of 10 basic attributes of HTML tables

Related recommendations:

htmlTable attributes_html/css_WEB -ITnose

Detailed explanation of the frame and rules attributes of table tables in HTML

The above is the detailed content of What are the HTML table attributes? Summary of 10 basic attributes of HTML tables. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template