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?
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.
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 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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With