: The Table Data Cell Element - HTML - MDN Web Docs - Mozilla
Trang chủ » Html Table Stretch Row
»
: The Table Data Cell Element - HTML - MDN Web Docs - Mozilla
Có thể bạn quan tâm
- Skip to main content
- Skip to search
- Skip to select language
- References
- HTML
- Elements
- <td>
Article Actions- English (US)
- Remember language
- Deutsch
- Español
- Français
- 日本語
- Русский
- Try it
- Attributes
- Usage notes
- Examples
- Technical summary
- Specifications
- Browser compatibility
- See also
- HTML
- Tutorials
- HTML basics
- Introduction to HTML
- Introduction to HTML overview
- Getting started with HTML
- What's in the head? Metadata in HTML
- HTML text fundamentals
- Creating hyperlinks
- Advanced text formatting
- Document and website structure
- Debugging HTML
- Assessment: Marking up a letter
- Assessment: Structuring a page of content
- Multimedia and embedding
- Multimedia and embedding overview
- Images in HTML
- Video and audio content
- From object to iframe — other embedding technologies
- Adding vector graphics to the web
- Responsive images
- Assessment: Mozilla splash page
- HTML tables
- HTML tables overview
- HTML table basics
- HTML table advanced features and accessibility
- Assessment: Structuring planet data
- References
- HTML elements
- <a>
- <abbr>
- <acronym> Deprecated
- <address>
- <area>
- <article>
- <aside>
- <audio>
- <b>
- <base>
- <bdi>
- <bdo>
- <big> Deprecated
- <blockquote>
- <body>
- <br>
- <button>
- <canvas>
- <caption>
- <center> Deprecated
- <cite>
- <code>
- <col>
- <colgroup>
- <data>
- <datalist>
- <dd>
- <del>
- <details>
- <dfn>
- <dialog>
- <dir> Deprecated
- <div>
- <dl>
- <dt>
- <em>
- <embed>
- <fencedframe> Experimental
- <fieldset>
- <figcaption>
- <figure>
- <font> Deprecated
- <footer>
- <form>
- <frame> Deprecated
- <frameset> Deprecated
- <h1>
- <head>
- <header>
- <hgroup>
- <hr>
- <html>
- <i>
- <iframe>
- <img>
- <input>
- <ins>
- <kbd>
- <label>
- <legend>
- <li>
- <link>
- <main>
- <map>
- <mark>
- <marquee> Deprecated
- <menu>
- <meta>
- <meter>
- <nav>
- <nobr> Deprecated
- <noembed> Deprecated
- <noframes> Deprecated
- <noscript>
- <object>
- <ol>
- <optgroup>
- <option>
- <output>
- <p>
- <param> Deprecated
- <picture>
- <plaintext> Deprecated
- <portal> Experimental
- <pre>
- <progress>
- <q>
- <rb> Deprecated
- <rp>
- <rt>
- <rtc> Deprecated
- <ruby>
- <s>
- <samp>
- <script>
- <search>
- <section>
- <select>
- <slot>
- <small>
- <source>
- <span>
- <strike> Deprecated
- <strong>
- <style>
- <sub>
- <summary>
- <sup>
- <table>
- <tbody>
- <td>
- <template>
- <textarea>
- <tfoot>
- <th>
- <thead>
- <time>
- <title>
- <tr>
- <track>
- <tt> Deprecated
- <u>
- <ul>
- <var>
- <video>
- <wbr>
- <xmp> Deprecated
- Global attributes
- accesskey
- anchor Experimental Non-standard
- autocapitalize
- autocorrect Experimental
- autofocus
- class
- contenteditable
- data-*
- dir
- draggable
- enterkeyhint
- exportparts
- hidden
- id
- inert
- inputmode
- is
- itemid
- itemprop
- itemref
- itemscope
- itemtype
- lang
- nonce
- part
- popover
- slot
- spellcheck
- style
- tabindex
- title
- translate
- virtualkeyboardpolicy Experimental
- writingsuggestions
- Attributes
- accept
- autocomplete
- capture
- crossorigin
- dirname
- disabled
- elementtiming
- for
- max
- maxlength
- min
- minlength
- multiple
- pattern
- placeholder
- readonly
- rel
- required
- size
- step
- <input> types
- <input type="button">
- <input type="checkbox">
- <input type="color">
- <input type="date">
- <input type="datetime-local">
- <input type="email">
- <input type="file">
- <input type="hidden">
- <input type="image">
- <input type="month">
- <input type="number">
- <input type="password">
- <input type="radio">
- <input type="range">
- <input type="reset">
- <input type="search">
- <input type="submit">
- <input type="tel">
- <input type="text">
- <input type="time">
- <input type="url">
- <input type="week">
- Guides
-
- Content categories
- Block-level elements
- Inline elements
- Quirks Mode and Standards Mode
- Date and time formats used in HTML
- Constraint validation
- Microdata
- Microformats
- Viewport meta tag
- Allowing cross-origin use of images and canvas
- Try it
- Attributes
- Usage notes
- Examples
- Technical summary
- Specifications
- Browser compatibility
- See also
The <td> HTML element defines a cell of a table that contains data and may be used as a child of the <tr> element.
Try it
Attributes
This element includes the global attributes.
colspan Contains a non-negative integer value that indicates how many columns the data cell spans or extends. The default value is 1. User agents dismiss values higher than 1000 as incorrect, setting to the default value (1).
headers Contains a list of space-separated strings, each corresponding to the id attribute of the <th> elements that provide headings for this table cell.
rowspan Contains a non-negative integer value that indicates for how many rows the data cell spans or extends. The default value is 1; if its value is set to 0, it extends until the end of the table grouping section (<thead>, <tbody>, <tfoot>, even if implicitly defined), that the cell belongs to. Values higher than 65534 are clipped to 65534.
Deprecated attributes
The following attributes are deprecated and should not be used. They are documented below for reference when updating existing code and for historical interest only.
abbr Deprecated Contains a short abbreviated description of the data cell's content. Some user-agents, such as speech readers, may present this description before the content itself. Put the abbreviated content inside the cell and place the (longer) description in the title attribute, as this attribute is deprecated. Or, preferably, include the content within the data cell, and use CSS to visually clip overflowing text.
align Deprecated Specifies the horizontal alignment of the data cell. The possible enumerated values are left, center, right, justify, and char. When supported, the char value aligns the textual content on the character defined in the char attribute and the offset defined by the charoff attribute. Use the text-align CSS property instead, as this attribute is deprecated.
axis Deprecated Contains a list of space-separated strings, each corresponding to the id attribute of a group of cells that the data cell applies to.
bgcolor Deprecated Defines the background color of the data cell. The value is an HTML color; either a 6-digit hexadecimal RGB code, prefixed by a #, or a color keyword. Other CSS <color> values are not supported. Use the background-color CSS property instead, as this attribute is deprecated.
char Deprecated Does nothing. It was originally intended to specify the alignment of the content to a character of the data cell. Typical values for this include a period (.) when attempting to align numbers or monetary values. If align is not set to char, this attribute is ignored.
charoff Deprecated Does nothing. It was originally intended to specify the number of characters to offset the data cell content from the alignment character specified by the char attribute.
height Deprecated Defines a recommended data cell height. Use the height CSS property instead, as this attribute is deprecated.
scope Deprecated Defines the cells that the header (defined in the <th>) element relates to. The possible enumerated values are row, col, rowgroup, and colgroup. Only use this attribute with the <th> element to define the row or column for which it is a header, as this attribute is deprecated for the <td> element.
valign Deprecated Specifies the vertical alignment of the data cell. The possible enumerated values are baseline, bottom, middle, and top. Use the vertical-align CSS property instead, as this attribute is deprecated.
width Deprecated Defines a recommended data cell width. Use the width CSS property instead, as this attribute is deprecated.
Usage notes
-
The <td> may only be used within a <tr> element.
-
When using the colspan and rowspan attributes to span data cells across multiple columns and rows, cells without these attributes defined (with a default value of 1) are automatically fitted into free available spaces in the table structure that span 1x1 cells, as illustrated in the following figure:
Note: These attributes must not be used to overlap cells.
Examples
See <table> for a complete table example introducing common standards and best practices.
Basic data cells
This example uses <td> elements along with other table-related elements to introduce a basic table with data about the phonetic alphabet.
HTML
Some table rows (<tr> elements) contain both header cells (<th> elements) and data cell <td> elements. The <th> element that is the first child of each row forms the first column of the table, with each <th> providing the row header for the data cells within that row. Each corresponding <td> element contains data aligned with its respective column header and row header cell.
Note: Normally, a table head group with column headers would be implemented to make it easier to understand the information in the columns. The <thead> and <tbody> elements would be used to group such rows of headers and data into the respective table head and body sections. This is not implemented in this example to focus on the data cells and reduce the complexity of this example.
html<table> <tr> <th scope="row">A</th> <td>Alfa</td> <td>AL fah</td> </tr> <tr> <th scope="row">B</th> <td>Bravo</td> <td>BRAH voh</td> </tr> <tr> <th scope="row">C</th> <td>Charlie</td> <td>CHAR lee</td> </tr> <tr> <th scope="row">D</th> <td>Delta</td> <td>DELL tah</td> </tr> </table> CSS
Some basic CSS is used to style the table and its cells. CSS attribute selectors and the :nth-of-type pseudo-class are used to alternate the appearance of the cells to make the information in the table easier to understand and identify.
csstd, th { border: 1px solid rgb(160 160 160); padding: 8px 10px; } tr:nth-of-type(odd) td { background-color: #eee; } tr th[scope="row"] { background-color: #d6ecd4; } table { border-collapse: collapse; border: 2px solid rgb(140 140 140); font-family: sans-serif; font-size: 0.8rem; letter-spacing: 1px; } Result
Column and row spanning
This example extends and enhances the basic table from the previous example by adding an additional "ABC" cell.
HTML
An additional data cell (<td> element) is introduced within the first row (<tr> element). This creates a fourth column in the table.
Using the rowspan attribute, the "ABC" cell is spanned across the first three rows of the table. The last data cells of the subsequent rows each span two columns. This is done using the colspan attribute, aligning them correctly within the table structure. Note that an additional row (<tr> element) is added to the table to illustrate this.
html<table> <tr> <th scope="row">A</th> <td>Alfa</td> <td>AL fah</td> <td rowspan="3">ABC</td> </tr> <tr> <th scope="row">B</th> <td>Bravo</td> <td>BRAH voh</td> </tr> <tr> <th scope="row">C</th> <td>Charlie</td> <td>CHAR lee</td> </tr> <tr> <th scope="row">D</th> <td>Delta</td> <td colspan="2">DELL tah</td> </tr> <tr> <th scope="row">E</th> <td>Echo</td> <td colspan="2">ECK oh</td> </tr> </table> CSS
The :first-of-type and :last-of-type pseudo-classes are used in the CSS to select and style the added "ABC" data cell.
csstr:first-of-type td:last-of-type { width: 60px; background-color: #505050; color: #fff; font-weight: bold; text-align: center; } td, th { border: 1px solid rgb(160 160 160); padding: 8px 10px; } tr:nth-of-type(odd) td { background-color: #eee; } tr th[scope="row"] { background-color: #d6ecd4; } table { border-collapse: collapse; border: 2px solid rgb(140 140 140); font-family: sans-serif; font-size: 0.8rem; letter-spacing: 1px; } Result
Associate data cells with header cells
For more complex relationships between data cells (<td> elements) and header cells (<th> elements), using <th> elements with the scope attribute alone may not be sufficient for assistive technologies, especially screen readers.
HTML
To improve the accessibility of the previous example and to allow screen readers, for example, to speak the headers associated with each data cell, the headers attribute can be introduced along with id attributes. Each row header cell (<th> element) associated with the "ABC" data cell, i.e., the letters "A", "B", and "C", is given a unique identifier with the id attribute. The "ABC" data cell (<td> element) then uses these id values in a space-separated list for the headers attribute.
Note: It's recommended to use more descriptive and useful values for the id attribute. Each id in a document must be unique to that document. In this example, the id values are single characters to maintain focus on the concept of the headers attribute.
html<table> <tr> <th id="a" scope="row">A</th> <td>Alfa</td> <td>AL fah</td> <td headers="a b c" rowspan="3">ABC</td> </tr> <tr> <th id="b" scope="row">B</th> <td>Bravo</td> <td>BRAH voh</td> </tr> <tr> <th id="c" scope="row">C</th> <td>Charlie</td> <td>CHAR lee</td> </tr> <tr> <th scope="row">D</th> <td>Delta</td> <td colspan="2">DELL tah</td> </tr> <tr> <th scope="row">E</th> <td>Echo</td> <td colspan="2">ECK oh</td> </tr> </table> Result
While the visual result is unchanged from the previous example table, each data cell (<td>) is now explicitly associated with its row header cell (<th>).
Technical summary
Content categories Sectioning root. Permitted content Flow content. Tag omission The start tag is mandatory.The end tag may be omitted, if it is immediately followed by a <th> or <td> element or if there are no more data in its parent element. Permitted parents A <tr> element. Implicit ARIA role cell if a descendant of a <table> element Permitted ARIA roles Any DOM interface HTMLTableCellElement
Specifications
Specification HTML Standard # the-td-element
Browser compatibility
BCD tables only load in the browser
See also
- Learn: HTML tables
- <caption>, <col>, <colgroup>, <table>, <tbody>, <tfoot>, <th>, <thead>, <tr>: Other table-related elements
- background-color: CSS property to set the background color of each data cell
- border: CSS property to control borders of data cells
- height: CSS property to control the recommended data cell height
- text-align: CSS property to horizontally align each data cell content
- vertical-align: CSS property to vertically align each data cell content
- width: CSS property to control the recommended data cell width
- :nth-of-type, :first-of-type, :last-of-type: CSS pseudo-classes to select the desired data cells
Help improve MDN
Was this page helpful to you?YesNoLearn how to contribute.This page was last modified on Sep 25, 2024 by MDN contributors.
View this page on GitHub • Report a problem with this content
Từ khóa » Html Table Stretch Row
-
How To Make A Table Cell Stretch For The Rest Of The Width? [duplicate]
-
Having A Table-cell Stretch - HTML & CSS - SitePoint Forums
-
Table Row And Column Spanning - Home And Learn
-
Table-layout - CSS-Tricks
-
How To Create A Full Width Table - W3Schools
-
CSS Table-layout Property - W3Schools
-
Table-layout - CSS: Cascading Style Sheets - MDN Web Docs
-
Tables - W3C
-
HTML Tables: All There Is To Know About Them - FreeCodeCamp
-
Advanced Table Settings: Column Width, Alignment And Merging Cells
-
Stop Using To Set Table Width In HTML: Here's Why »
-
How To Set HTML Table Width And Height
-
A Way To Stretch Only The BOTTOM Table Cell To Fill 100% Page Height?
-
Prevent Long Strings From Stretching Your
With CSS
Liên Hệ
TRUYỀN HÌNH CÁP SÔNG THU ĐÀ NẴNG
Địa Chỉ: 58 Hàm Nghi - Đà Nẵng
Phone: 0904961917
Facebook: https://fb.com/truyenhinhcapsongthu/
Twitter: @ Capsongthu
Copyright © 2022 | Thiết Kế Truyền Hình Cáp Sông Thu
Trang chủ » Html Table Stretch Row »
Có thể bạn quan tâm
- Skip to main content
- Skip to search
- Skip to select language
- References
- HTML
- Elements
- <td>
- English (US)
- Remember language
- Deutsch
- Español
- Français
- 日本語
- Русский
- Try it
- Attributes
- Usage notes
- Examples
- Technical summary
- Specifications
- Browser compatibility
- See also
- HTML
- Tutorials
- HTML basics
- Introduction to HTML
- Introduction to HTML overview
- Getting started with HTML
- What's in the head? Metadata in HTML
- HTML text fundamentals
- Creating hyperlinks
- Advanced text formatting
- Document and website structure
- Debugging HTML
- Assessment: Marking up a letter
- Assessment: Structuring a page of content
- Multimedia and embedding
- Multimedia and embedding overview
- Images in HTML
- Video and audio content
- From object to iframe — other embedding technologies
- Adding vector graphics to the web
- Responsive images
- Assessment: Mozilla splash page
- HTML tables
- HTML tables overview
- HTML table basics
- HTML table advanced features and accessibility
- Assessment: Structuring planet data
- References
- HTML elements
- <a>
- <abbr>
- <acronym> Deprecated
- <address>
- <area>
- <article>
- <aside>
- <audio>
- <b>
- <base>
- <bdi>
- <bdo>
- <big> Deprecated
- <blockquote>
- <body>
- <br>
- <button>
- <canvas>
- <caption>
- <center> Deprecated
- <cite>
- <code>
- <col>
- <colgroup>
- <data>
- <datalist>
- <dd>
- <del>
- <details>
- <dfn>
- <dialog>
- <dir> Deprecated
- <div>
- <dl>
- <dt>
- <em>
- <embed>
- <fencedframe> Experimental
- <fieldset>
- <figcaption>
- <figure>
- <font> Deprecated
- <footer>
- <form>
- <frame> Deprecated
- <frameset> Deprecated
- <h1>
- <head>
- <header>
- <hgroup>
- <hr>
- <html>
- <i>
- <iframe>
- <img>
- <input>
- <ins>
- <kbd>
- <label>
- <legend>
- <li>
- <link>
- <main>
- <map>
- <mark>
- <marquee> Deprecated
- <menu>
- <meta>
- <meter>
- <nav>
- <nobr> Deprecated
- <noembed> Deprecated
- <noframes> Deprecated
- <noscript>
- <object>
- <ol>
- <optgroup>
- <option>
- <output>
- <p>
- <param> Deprecated
- <picture>
- <plaintext> Deprecated
- <portal> Experimental
- <pre>
- <progress>
- <q>
- <rb> Deprecated
- <rp>
- <rt>
- <rtc> Deprecated
- <ruby>
- <s>
- <samp>
- <script>
- <search>
- <section>
- <select>
- <slot>
- <small>
- <source>
- <span>
- <strike> Deprecated
- <strong>
- <style>
- <sub>
- <summary>
- <sup>
- <table>
- <tbody>
- <td>
- <template>
- <textarea>
- <tfoot>
- <th>
- <thead>
- <time>
- <title>
- <tr>
- <track>
- <tt> Deprecated
- <u>
- <ul>
- <var>
- <video>
- <wbr>
- <xmp> Deprecated
- Global attributes
- accesskey
- anchor Experimental Non-standard
- autocapitalize
- autocorrect Experimental
- autofocus
- class
- contenteditable
- data-*
- dir
- draggable
- enterkeyhint
- exportparts
- hidden
- id
- inert
- inputmode
- is
- itemid
- itemprop
- itemref
- itemscope
- itemtype
- lang
- nonce
- part
- popover
- slot
- spellcheck
- style
- tabindex
- title
- translate
- virtualkeyboardpolicy Experimental
- writingsuggestions
- Attributes
- accept
- autocomplete
- capture
- crossorigin
- dirname
- disabled
- elementtiming
- for
- max
- maxlength
- min
- minlength
- multiple
- pattern
- placeholder
- readonly
- rel
- required
- size
- step
- <input> types
- <input type="button">
- <input type="checkbox">
- <input type="color">
- <input type="date">
- <input type="datetime-local">
- <input type="email">
- <input type="file">
- <input type="hidden">
- <input type="image">
- <input type="month">
- <input type="number">
- <input type="password">
- <input type="radio">
- <input type="range">
- <input type="reset">
- <input type="search">
- <input type="submit">
- <input type="tel">
- <input type="text">
- <input type="time">
- <input type="url">
- <input type="week">
- Guides
-
- Content categories
- Block-level elements
- Inline elements
- Quirks Mode and Standards Mode
- Date and time formats used in HTML
- Constraint validation
- Microdata
- Microformats
- Viewport meta tag
- Allowing cross-origin use of images and canvas
- Try it
- Attributes
- Usage notes
- Examples
- Technical summary
- Specifications
- Browser compatibility
- See also
The <td> HTML element defines a cell of a table that contains data and may be used as a child of the <tr> element.
Try it
Attributes
This element includes the global attributes.
colspanContains a non-negative integer value that indicates how many columns the data cell spans or extends. The default value is 1. User agents dismiss values higher than 1000 as incorrect, setting to the default value (1).
headersContains a list of space-separated strings, each corresponding to the id attribute of the <th> elements that provide headings for this table cell.
rowspanContains a non-negative integer value that indicates for how many rows the data cell spans or extends. The default value is 1; if its value is set to 0, it extends until the end of the table grouping section (<thead>, <tbody>, <tfoot>, even if implicitly defined), that the cell belongs to. Values higher than 65534 are clipped to 65534.
Deprecated attributes
The following attributes are deprecated and should not be used. They are documented below for reference when updating existing code and for historical interest only.
abbr DeprecatedContains a short abbreviated description of the data cell's content. Some user-agents, such as speech readers, may present this description before the content itself. Put the abbreviated content inside the cell and place the (longer) description in the title attribute, as this attribute is deprecated. Or, preferably, include the content within the data cell, and use CSS to visually clip overflowing text.
align DeprecatedSpecifies the horizontal alignment of the data cell. The possible enumerated values are left, center, right, justify, and char. When supported, the char value aligns the textual content on the character defined in the char attribute and the offset defined by the charoff attribute. Use the text-align CSS property instead, as this attribute is deprecated.
axis DeprecatedContains a list of space-separated strings, each corresponding to the id attribute of a group of cells that the data cell applies to.
bgcolor DeprecatedDefines the background color of the data cell. The value is an HTML color; either a 6-digit hexadecimal RGB code, prefixed by a #, or a color keyword. Other CSS <color> values are not supported. Use the background-color CSS property instead, as this attribute is deprecated.
char DeprecatedDoes nothing. It was originally intended to specify the alignment of the content to a character of the data cell. Typical values for this include a period (.) when attempting to align numbers or monetary values. If align is not set to char, this attribute is ignored.
charoff DeprecatedDoes nothing. It was originally intended to specify the number of characters to offset the data cell content from the alignment character specified by the char attribute.
height DeprecatedDefines a recommended data cell height. Use the height CSS property instead, as this attribute is deprecated.
scope DeprecatedDefines the cells that the header (defined in the <th>) element relates to. The possible enumerated values are row, col, rowgroup, and colgroup. Only use this attribute with the <th> element to define the row or column for which it is a header, as this attribute is deprecated for the <td> element.
valign DeprecatedSpecifies the vertical alignment of the data cell. The possible enumerated values are baseline, bottom, middle, and top. Use the vertical-align CSS property instead, as this attribute is deprecated.
width DeprecatedDefines a recommended data cell width. Use the width CSS property instead, as this attribute is deprecated.
Usage notes
-
The <td> may only be used within a <tr> element.
-
When using the colspan and rowspan attributes to span data cells across multiple columns and rows, cells without these attributes defined (with a default value of 1) are automatically fitted into free available spaces in the table structure that span 1x1 cells, as illustrated in the following figure:
Note: These attributes must not be used to overlap cells.
Examples
See <table> for a complete table example introducing common standards and best practices.
Basic data cells
This example uses <td> elements along with other table-related elements to introduce a basic table with data about the phonetic alphabet.
HTML
Some table rows (<tr> elements) contain both header cells (<th> elements) and data cell <td> elements. The <th> element that is the first child of each row forms the first column of the table, with each <th> providing the row header for the data cells within that row. Each corresponding <td> element contains data aligned with its respective column header and row header cell.
Note: Normally, a table head group with column headers would be implemented to make it easier to understand the information in the columns. The <thead> and <tbody> elements would be used to group such rows of headers and data into the respective table head and body sections. This is not implemented in this example to focus on the data cells and reduce the complexity of this example.
html<table> <tr> <th scope="row">A</th> <td>Alfa</td> <td>AL fah</td> </tr> <tr> <th scope="row">B</th> <td>Bravo</td> <td>BRAH voh</td> </tr> <tr> <th scope="row">C</th> <td>Charlie</td> <td>CHAR lee</td> </tr> <tr> <th scope="row">D</th> <td>Delta</td> <td>DELL tah</td> </tr> </table>CSS
Some basic CSS is used to style the table and its cells. CSS attribute selectors and the :nth-of-type pseudo-class are used to alternate the appearance of the cells to make the information in the table easier to understand and identify.
csstd, th { border: 1px solid rgb(160 160 160); padding: 8px 10px; } tr:nth-of-type(odd) td { background-color: #eee; } tr th[scope="row"] { background-color: #d6ecd4; } table { border-collapse: collapse; border: 2px solid rgb(140 140 140); font-family: sans-serif; font-size: 0.8rem; letter-spacing: 1px; }Result
Column and row spanning
This example extends and enhances the basic table from the previous example by adding an additional "ABC" cell.
HTML
An additional data cell (<td> element) is introduced within the first row (<tr> element). This creates a fourth column in the table.
Using the rowspan attribute, the "ABC" cell is spanned across the first three rows of the table. The last data cells of the subsequent rows each span two columns. This is done using the colspan attribute, aligning them correctly within the table structure. Note that an additional row (<tr> element) is added to the table to illustrate this.
html<table> <tr> <th scope="row">A</th> <td>Alfa</td> <td>AL fah</td> <td rowspan="3">ABC</td> </tr> <tr> <th scope="row">B</th> <td>Bravo</td> <td>BRAH voh</td> </tr> <tr> <th scope="row">C</th> <td>Charlie</td> <td>CHAR lee</td> </tr> <tr> <th scope="row">D</th> <td>Delta</td> <td colspan="2">DELL tah</td> </tr> <tr> <th scope="row">E</th> <td>Echo</td> <td colspan="2">ECK oh</td> </tr> </table>CSS
The :first-of-type and :last-of-type pseudo-classes are used in the CSS to select and style the added "ABC" data cell.
csstr:first-of-type td:last-of-type { width: 60px; background-color: #505050; color: #fff; font-weight: bold; text-align: center; } td, th { border: 1px solid rgb(160 160 160); padding: 8px 10px; } tr:nth-of-type(odd) td { background-color: #eee; } tr th[scope="row"] { background-color: #d6ecd4; } table { border-collapse: collapse; border: 2px solid rgb(140 140 140); font-family: sans-serif; font-size: 0.8rem; letter-spacing: 1px; }Result
Associate data cells with header cells
For more complex relationships between data cells (<td> elements) and header cells (<th> elements), using <th> elements with the scope attribute alone may not be sufficient for assistive technologies, especially screen readers.
HTML
To improve the accessibility of the previous example and to allow screen readers, for example, to speak the headers associated with each data cell, the headers attribute can be introduced along with id attributes. Each row header cell (<th> element) associated with the "ABC" data cell, i.e., the letters "A", "B", and "C", is given a unique identifier with the id attribute. The "ABC" data cell (<td> element) then uses these id values in a space-separated list for the headers attribute.
Note: It's recommended to use more descriptive and useful values for the id attribute. Each id in a document must be unique to that document. In this example, the id values are single characters to maintain focus on the concept of the headers attribute.
html<table> <tr> <th id="a" scope="row">A</th> <td>Alfa</td> <td>AL fah</td> <td headers="a b c" rowspan="3">ABC</td> </tr> <tr> <th id="b" scope="row">B</th> <td>Bravo</td> <td>BRAH voh</td> </tr> <tr> <th id="c" scope="row">C</th> <td>Charlie</td> <td>CHAR lee</td> </tr> <tr> <th scope="row">D</th> <td>Delta</td> <td colspan="2">DELL tah</td> </tr> <tr> <th scope="row">E</th> <td>Echo</td> <td colspan="2">ECK oh</td> </tr> </table>Result
While the visual result is unchanged from the previous example table, each data cell (<td>) is now explicitly associated with its row header cell (<th>).
Technical summary
Content categories | Sectioning root. |
---|---|
Permitted content | Flow content. |
Tag omission | The start tag is mandatory.The end tag may be omitted, if it is immediately followed by a <th> or <td> element or if there are no more data in its parent element. |
Permitted parents | A <tr> element. |
Implicit ARIA role | cell if a descendant of a <table> element |
Permitted ARIA roles | Any |
DOM interface | HTMLTableCellElement |
Specifications
Specification |
---|
HTML Standard # the-td-element |
Browser compatibility
BCD tables only load in the browser
See also
- Learn: HTML tables
- <caption>, <col>, <colgroup>, <table>, <tbody>, <tfoot>, <th>, <thead>, <tr>: Other table-related elements
- background-color: CSS property to set the background color of each data cell
- border: CSS property to control borders of data cells
- height: CSS property to control the recommended data cell height
- text-align: CSS property to horizontally align each data cell content
- vertical-align: CSS property to vertically align each data cell content
- width: CSS property to control the recommended data cell width
- :nth-of-type, :first-of-type, :last-of-type: CSS pseudo-classes to select the desired data cells
Help improve MDN
Was this page helpful to you?YesNoLearn how to contribute.This page was last modified on Sep 25, 2024 by MDN contributors.
View this page on GitHub • Report a problem with this contentTừ khóa » Html Table Stretch Row
-
How To Make A Table Cell Stretch For The Rest Of The Width? [duplicate]
-
Having A Table-cell Stretch - HTML & CSS - SitePoint Forums
-
Table Row And Column Spanning - Home And Learn
-
Table-layout - CSS-Tricks
-
How To Create A Full Width Table - W3Schools
-
CSS Table-layout Property - W3Schools
-
Table-layout - CSS: Cascading Style Sheets - MDN Web Docs
-
Tables - W3C
-
HTML Tables: All There Is To Know About Them - FreeCodeCamp
-
Advanced Table Settings: Column Width, Alignment And Merging Cells
-
Stop Using To Set Table Width In HTML: Here's Why »
-
How To Set HTML Table Width And Height
-
A Way To Stretch Only The BOTTOM Table Cell To Fill 100% Page Height?
-
Prevent Long Strings From Stretching Your
With CSS
Liên Hệ
TRUYỀN HÌNH CÁP SÔNG THU ĐÀ NẴNG
Địa Chỉ: 58 Hàm Nghi - Đà Nẵng
Phone: 0904961917
Facebook: https://fb.com/truyenhinhcapsongthu/
Twitter: @ Capsongthu
Copyright © 2022 | Thiết Kế Truyền Hình Cáp Sông Thu