Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easy styling of all Td's in a table or in a div

Is there a way I can use one category to stylize all of my table cells? I cant just use

td{

}

because I have another table on the same page that I don't want the same style on. The table I want to stylize has around 40 cells, so is there a way to collectively style them short of copy-pasting a class or id 40 times?

like image 883
Wilson Avatar asked Jun 14 '12 15:06

Wilson


People also ask

Should I use table or div?

In general, try to use TABLE for true tables of data, use DIV and SPAN for logical block or inline containers of content. Show activity on this post. Tables should only be used to display data in a tabular way. For layout and design it is best practise to use divs and stylesheets.

How can CSS be used to style a table?

CSS provides a number of attributes for styling tables. These attributes allow you to—among other things—separate cells in a table, specify table borders, and specify the width and height of a table. This tutorial will discuss, with examples, how to style a table using CSS.


2 Answers

Put a selector on the table tag:

<table class="my-special-table">
<tr><td></td></tr>
</table>

table.my-special-table td { style it up! }
like image 81
Lowkase Avatar answered Sep 23 '22 02:09

Lowkase


If your table has a specific attribute such an as ID, you can reference it in CSS specifically:

<table id="myStyledTable">
    <tr>
        <td>...

Like so:

#myStyledTable td {

}
like image 28
Ben Roux Avatar answered Sep 23 '22 02:09

Ben Roux