Style Table Row With TH + TD - HTML & CSS - SitePoint Forums Trang chủ » Html Bold Line In Table » Style Table Row With TH + TD - HTML & CSS - SitePoint Forums Có thể bạn quan tâm Html Bootstrap Col-md Html Bootstrap Col-md-12 Html Bootstrap Col-md-3 Html Bootstrap Col-md-4 Html Bootstrap Col Size Loading Style table row with TH + TD HTML & CSS UpstateLeafPeeper January 5, 2021, 11:12pm 1 Is there an easy way to style a table row which has both a TH and TD’s? <tr> <th>Rain Coat</th> <td>Child's</td> <td>Yellow</td> <td>$39.99</td> </tr> If I add a class to TR then it just styles the TD’s. And it’s a pain to have to add a class to TR and the TH. chrisofarabia January 5, 2021, 11:37pm 2 This seems to cover it with what looks to be a decent example. : The Table Header element - HTML: HyperText Markup Language | MDN The HTML element defines a cell as the header of a group of table cells. The exact nature of this group is defined by the scope and headers attributes. 1 Like UpstateLeafPeeper January 5, 2021, 11:41pm 3 @chrisofarabia, Huh? There is no example. You gae a link to the MDN manual which says nothing about my OP and which I have already read… Ray.H January 6, 2021, 1:15am 4 UpstateLeafPeeper: If I add a class to TR then it just styles the TD’s. I’m guessing you are wanting to zebra stripe your rows. In one of your other threads the th had a bg-color set on it. That bg-color would layer on top of the rows bg-color and cause a conflict. If your wanting zebra stripe remove the bg-color from the th and style the rows with a bg-color. UpstateLeafPeeper January 6, 2021, 2:15am 5 @Ray.H, No. I want an easy way to make a row of data in the < tbody > to be all bold or a certain text color. I turned off bold on TH in the TBODY because I don’t normally like that. But now I need an entire row to be bold, i.e. TBODY TH and TBODY TD’s <tr> <th>Rain Coat</th> <td>Child's</td> <td>Yellow</td> <td>$39.99</td> </tr> If I have this style… .bold{ font-weight: bold; } And I add it like this… <tr class="bold> then it only bolds the TD’s in TBODY. So then I have to do this which is a pain… <tr class="bold> <th <tr class="bold>>Rain Coat</th> <td>Child's</td> <td>Yellow</td> <td>$39.99</td> </tr> tracknut January 6, 2021, 2:54am 6 Are you sure you don’t have some other styling for the th element, that has more specificity and therefore overriding your bold class on the tr? This code works fine to bold all the elements in the row: <!DOCTYPE html> <html> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <title>Untitled 1</title> <style> .bold {font-weight: bold} </style> </head> <body> <table> <tr class="bold"> <th>Rain Coat</th> <td>Child's</td> <td>Yellow</td> <td>$39.99</td> </tr> </table> </body> </html> Ray.H January 6, 2021, 2:59am 7 UpstateLeafPeeper: If I have this style… .bold{ font-weight: bold; } You were almost there, just add .bold th to it, comma separated. .bold, .bold th {font-weight:bold;} <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Test Page</title> <style> table { margin: 1em 2em; border-collapse: collapse; } td, th { border: 1px solid #000; padding: 4px; } th[scope="row"] { text-align:left; font-weight: normal; /*background:#eee; remove this*/ } th.arrow::before { content:'\27A4'; color: red; position: absolute; margin-left:-1.5em; } tbody tr:nth-child(odd) { background: yellow; } .bold, .bold th {font-weight:bold;} </style> </head> <body> <table> <thead> <tr> <th scope="col">Product</th> <th scope="col">Description</th> <th scope="col">Price</th> </tr> </thead> <tbody> <tr> <th scope="row">Men's Bathrobe</th> <td>Heavy, good for Winter...</td> <td>$35.99</td> </tr> <tr class="bold"> <th class="arrow" scope="row">Fuzzy Slippers</th> <td>Warm, cozy slippers...</td> <td>$19.99</td> </tr> <tr> <th scope="row">Flannel Shirt</th> <td>Heavy, good for Winter...</td> <td>$22.99</td> </tr> </tbody> </table> </body> </html> 3 Likes UpstateLeafPeeper January 6, 2021, 3:14am 8 @Ray.H, You’re the man!! It was a specificity issue as I guess you gathered… This code tbody th{ font-weight: normal; text-align: left; } was beating out this code .bold{ font-weight: bold; } So you’re code solves that issue and it makes my HTML cleaner. Thanks! P.S. Can you explain this code… th[scope="row"] { text-align:left; font-weight: normal; /*background:#eee; remove this*/ } Apparently that works the same as <th scope="row"></th> Ray.H January 6, 2021, 3:21am 9 UpstateLeafPeeper: Apparently that works the same as It’s an attribute selector, it was used in your other thread. It is targeting the row th so as not to remove the bold font from the thead col th. It keeps you from having to introduce another class in the html Had you just said… th {font-weight:normal} It would target both row and col th elements UpstateLeafPeeper: It was a specificity issue as I guess you gathered… Well you removed the default bold font so you had to put it back for that class only 2 Likes system Closed April 7, 2021, 10:21am 10 This topic was automatically closed 91 days after the last reply. New replies are no longer allowed. Related topics Topic Replies Views Activity Table style question HTML & CSS 4 488 February 23, 2011 Table striping? HTML & CSS 17 9605 August 16, 2015 Styling a Table Column HTML & CSS 20 1939 July 19, 2015 Tbody and padding HTML & CSS 6 13677 October 8, 2014 Nested table and child selector HTML & CSS 3 3146 October 8, 2014 Từ khóa » Html Bold Line In Table Bold Data In Row(tr) In Table In Html - CodeProject Bold A Single Line In Html Table [closed] - Stack Overflow HTML Table Borders - W3Schools Make Table Font Bold - Tags « HTML / CSS HTML: Tag - TechOnTheNet Bold Text In Table Html Code Example HTML Table Basics Solved: Change Format Of The Last Row Of A HTML Table Examples Of Table Borders And Rules - W3C Bold Rows Meeting Criteria In Embedded HTML Table In An Email Styling Tables - Learn Web Development | MDN Tables In HTML Documents Make Last Row Of Table "bold" - OutSystems Table Visualization — Pandas 1.4.3 Documentation Liên Hệ TRUYỀN HÌNH CÁP SÔNG THU ĐÀ NẴNG Địa Chỉ: 58 Hàm Nghi - Đà Nẵng Phone: 0904961917 Web: truyenhinhcapsongthu.net Facebook: https://fb.com/truyenhinhcapsongthu/ Twitter: @ Capsongthu Copyright © 2022 | Thiết Kế Truyền Hình Cáp Sông Thu