Home Web Front-end HTML Tutorial Summary of different table attributes of HTML (with code)

Summary of different table attributes of HTML (with code)

Jul 21, 2018 am 11:38 AM

This article shares with you a summary of the different table attributes of HTML (with code). The content is very good. Friends in need can refer to it. I hope it can help everyone.

Here we mainly summarize and record some attributes and simple styles of the table for future convenience.

1.

Used to define the table of HTML, with local attributes border represents the border, and 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

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

2,

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

The tr element can be used within the table, thead, tbody and tfoot elements

The tr element can contain one or more td Or th element

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

3,

Used to define the header of the table and the wrapper of the table 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 body of the table

6,

Used to define the body of the table

7,

Used to define the footer of the marked table

⚠️:

    , tags must have the tag inside them
  • tags, no matter where they are placed within the

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

     (1)colspan: column span, this attribute specifies the columns that the cell can span Number, the value of this 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, which associates the cells with column headers and can be used with screen readers

    ⚠️: Each The table must contain the above three elements

    A simple example

    <!DOCTYPE html><html>
        <body>
            <table>
                <tr>
                    <td>A</td>
                    <td>B</td>
                    <td>C</td>
                </tr>
                <tr>
                    <td>D</td>
                    <td>E</td>
                    <td>F</td>
                </tr>
            </table>
        </body></html>
    Copy after login

    The effect is as follows:

    4.

    Used to define the title cell so that we can effectively distinguish the data and its description

    It The same local attributes as the <td> element have the following differences:

    1. ##
    is the header Marker, 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.

    ## 5.
    tag, will be assigned to 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 after the or the last element
  • 8,

    Used to define table column groups, which can be used to apply styles to a certain column. Of course, you can also use the following The col element

    has the local attribute span

    indicating 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,

    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

    also has a local Attribute span

     

    is placed inside the element of , and 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,

    Used to define the title of the table, each The table can only contain one

    element

    A simple example:

    <!DOCTYPE html><html>
        <head>
            <style>
                thead th,tfoot th {
                    text-align: left;
                    background: grey;
                    color: white            }
                tbody th {
                    text-align: right;
                    background: lightgrey;
                    color: grey            }
                /* tbody td {
                    background: greenyellow;
                } */
                #colgroup1 {
                    background-color: blueviolet            }
                #col3 {
                    background-color: yellow;
                    font-size: small            }
            </style>
        </head>
        <body>
            <table>
                <colgroup id="colgroup1">
                    <col id="collAnd2" span="2"/>
                    <col id="col3"/>
                </colgroup>
                <colgroup id="colgroup2" span="2"></colgroup>
                <thead>
                    <tr>
                        <th>Rank</th>
                        <th>Name</th>
                        <th>Color</th>
                        <th colspan="2">Size & Votes</th>
                    </tr>
                </thead>
                <tfoot>
                    <tr>
                        <th>Rank Footer</th>
                        <th>Name Footer</th>
                        <th>Color Footer</th>
                        <th colspan="2">Size And Votes Footer</th>
                    </tr>
                </tfoot>
                <tbody>
                    <tr>
                        <th>Favorite:</th>
                        <td>XML</td>
                        <td>CSS</td>
                        <td>Java</td>
                        <td>IOS</td>
                    </tr>
                    <tr>
                        <th>2nd Favorite:</th>
                        <td>Web</td>
                        <td>HTML5</td>
                        <td>CS</td>
                        <td>460</td>
                    </tr>
                </tbody>
            </table>
        </body></html>
    Copy after login

    View Code

    The effect is as follows:

    Related recommendations:

    Introduction to how to dynamically generate html elements and add attributes to elements (with code)

    The above is the detailed content of Summary of different table attributes of HTML (with code). 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 AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    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)

    Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

    HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

    The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

    HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

    What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

    AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

    Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

    WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

    Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Apr 04, 2025 pm 11:54 PM

    GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

    How to implement adaptive layout of Y-axis position in web annotation? How to implement adaptive layout of Y-axis position in web annotation? Apr 04, 2025 pm 11:30 PM

    The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...

    HTML, CSS, and JavaScript: Essential Tools for Web Developers HTML, CSS, and JavaScript: Essential Tools for Web Developers Apr 09, 2025 am 12:12 AM

    HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

    How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? Apr 05, 2025 am 06:15 AM

    To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

    See all articles