For A Column Instead Of Row? - Stack Overflow

Just browsing Stack Overflow? Help us improve your experience. Sign up for research
    1. Home
    2. Questions
    3. Tags
    4. Users
    5. Companies
    6. Labs
    7. Jobs
    8. Discussions
    9. Collectives
    10. Communities for your favorite technologies. Explore all Collectives

  1. Teams

    Ask questions, find answers and collaborate at work with Stack Overflow for Teams.

    Try Teams for free Explore Teams
  2. Teams
  3. Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Get early access and see previews of new features.

Learn more about Labs <th> for a column instead of row? Ask Question Asked 11 years, 10 months ago Modified 6 years, 9 months ago Viewed 7k times 7

Consider the following HTML:

<table> <tr> <td>Born</td> <td><time datetime="1986-11-05">5<sup>th</sup> November 1986</time></td> </tr> <tr> <td>Gender</td> <td>Male</td> </tr> <tr> <td>Sports</td> <td>Football<br />Tennis</td> </tr> <tr> <td>Teams</td> <td>Liverpool FC<br />Spain FC</td> </tr> </table>

Is it possible to use <th> in reference to a column, rather than a row? I'd like the left column bold.

Share Improve this question Follow edited Feb 15, 2018 at 18:16 Brian Tompsett - 汤莱恩's user avatar Brian Tompsett - 汤莱恩 5,87572 gold badges60 silver badges133 bronze badges asked Feb 4, 2013 at 3:29 Danny Beckett's user avatar Danny BeckettDanny Beckett 20.8k25 gold badges111 silver badges142 bronze badges 1
  • 3 Bold is just a matter of CSS. <th> is an element with specific semantic meaning. – Matt Ball Commented Feb 4, 2013 at 3:32
Add a comment |

3 Answers 3

Sorted by: Reset to default Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first) 14

Yes, you can use <th> for cells in rows or columns.

<table> <tr> <th>Born</th> <td><time datetime="1986-11-05">5<sup>th</sup> November 1986</time></td> </tr> <tr> <th>Gender</th> <td>Male</td> </tr> ... Share Improve this answer Follow answered Feb 4, 2013 at 3:31 Brad's user avatar BradBrad 164k55 gold badges373 silver badges545 bronze badges 0 Add a comment | 12

The spec clearly says that a th element can provide header information for a column or for a row (or group of columns or rows). The attribute scope=row can be used to explicitly say that the header cell is a row header.

Using th vs. td has a few implications. The functional implication is that user agents may treat th in a special way, giving the user access to data cells by corresponding header information. This applies mostly to speech-baser agents. For this to be meaningful, the th cell should really provide identifying information for the data row or data column. In this case, the condition is satisfied. So you could and should use th instead of td, quite independently of the desired rendering.

The other implications are that by default, th element content is rendered in bold face and horizontally centered. If this is not regarded as appropriate, you can easily override it in CSS (or even in HTML). In your case, if you want the content to be bold but left-aligned, use th { text-align: left; }. (Another, perhaps better, style is to right-align row headers: th { text-align: right; }. Centering may look odd.)

Share Improve this answer Follow answered Feb 4, 2013 at 9:36 Jukka K. Korpela's user avatar Jukka K. KorpelaJukka K. Korpela 201k38 gold badges278 silver badges403 bronze badges Add a comment | 0

Or you can add that css to bold only the first column

table tr td:first-child{font-weight:bold;} Share Improve this answer Follow answered Feb 4, 2013 at 3:36 Jonathan de M.'s user avatar Jonathan de M.Jonathan de M. 9,7988 gold badges49 silver badges72 bronze badges 1
  • 1 This is what a <th> is for though. No point re-inventing the wheel. Thanks for the effort, however. – Danny Beckett Commented Feb 4, 2013 at 3:37
Add a comment |

Your Answer

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid …

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

Draft saved Draft discarded

Sign up or log in

Sign up using Google Sign up using Email and Password Submit

Post as a guest

Name Email

Required, but never shown

Post Your Answer Discard

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.

  • The Overflow Blog
  • Your docs are your infrastructure
  • Featured on Meta
  • More network sites to see advertising test [updated with phase 2]
  • We’re (finally!) going to the cloud!
  • Call for testers for an early access release of a Stack Overflow extension...
0 CSS - Is it possible to force a <th> to take up an entire row? 0 Is there a row alternative for <th> in HTML? 6 HTML <th> col attribute 0 separating <th> elements in a table 0 how to style a th element to look like a td 2 how to align data within <th> to look like row? 4 Can using a <th> tag after a <td> cause problems? 1 Different number of TH's compared to columns in table 1 How to place a column of TH in a row of TH 0 Why Does <th> Not Span 100% Width of the Row? HTML CSS

Hot Network Questions

  • Counting birds outside my house
  • What does GB Shaw mean when he says "like the butcher's wife in the old catch" here?
  • How can a scalar particle be differentiated, experimentally, from a vector particle? How can we tell?
  • How to deal with intensity difference between different colors
  • Spellcheck I Before E
  • What powers do police have to force people onto trains?
  • Publishing corollaries of previously published results
  • Meaning of "I love my love with an S—" in Richard Burton's "Arabian Nights"
  • How can I avoid overusing her/she or the character name when describing character action
  • Why did the angel strain or dislocate Yaakov's hip-socket?
  • Should sudo ask for root password?
  • What mechanism could cause a person not to cast a reflection?
  • How Can I Add a Payment to a Pledge?
  • Why gap between arrow-head and smooth line
  • Are there any examples of exponential algorithms that use a polynomial-time algorithm for a special case as a subroutine (exponentially many times)?
  • What is this Stardew Valley item?
  • Adjective meaning "with gaps" or "with holes"
  • Taking the sum of predicted probabilities from logit model?
  • Where on Earth do tides go out furthest?
  • What is small arch between two notes and how to play it?
  • Is it problematic to use percentages to describe a sample with less than 100 people?
  • Solving Large size problems in industry: Tips and Tricks
  • Can you please advise on kerning?
  • T47 to BSA bottom bracket adapter - good idea?
more hot questions Question feed Subscribe to RSS Question feed

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

lang-html

Từ khóa » Html Th Column