Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Style the first <td> column of a table differently

If I have a table with two columns, how do I specify a padding or any other css so that it is applied just for the first column of <td>s. Also how do I style an n-th column similarly?

like image 460
Shalin Avatar asked Mar 28 '13 05:03

Shalin


People also ask

How do I target the first column of a table in CSS?

The :first-child selector is a pseudo-class that allows you to target an element that is the first child element within its parent. See also :last-child, :nth-child, :nth-last_child, and :only-child selectors.

How do I style a specific column in CSS?

If you want to apply a style to a specific column or row (but not on others), use :nth-child() property from CSS3. This selector is used to apply a style to the element number 'n' inside a parent element.

How do I target first TD in CSS?

How to Select the First and Last <td> in a Row with CSS. In this snippet, you can find out how to select and style individual columns of your table, particularly the first and last <td> in the table row. For that, you need to use the child selector pseudo-classes: :first-child and :last-child.

Which selector add the style to the first row of the table?

The ::first-line selector is used to add a style to the first line of the specified selector. Note: The following properties can be used with ::first-line: font properties.


1 Answers

You could use the n-th child selector.

to target the nth element you could then use:

td:nth-child(n) {     /* your stuff here */ } 

(where n starts at 1)

like image 63
RRikesh Avatar answered Nov 01 '22 06:11

RRikesh