Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select first and last <th> only?

Tags:

css

html-table

My table has id="mytable". I'm trying to apply some CSS on the first and last <th> only. I tried this but it doesn't work.

#mytable th:first,
#mytable th:last{
 //css goes here
}
like image 868
sami Avatar asked Dec 21 '10 11:12

sami


People also ask

How do you choose your first and last child?

Using the following pseudo classes: :first-child means "select this element if it is the first child of its parent". :last-child means "select this element if it is the last child of its parent". Only element nodes (HTML tags) are affected, these pseudo-classes ignore text nodes.

How do you select the first th in CSS?

The :first-of-type selector in CSS allows you to target the first occurence of an element within its container. It is defined in the CSS Selectors Level 3 spec as a “structural pseudo-class”, meaning it is used to style content based on its relationship with parent and sibling content.

How do you select the first TR in a table?

You could also have table > thead > tr and then table > tbody > tr. So you might need to specify whether you want the first row from the thead or the tbody. find('tr:first') will select the tr in the thead. – Jeff S.

How do you select every element except first?

By using the :not(:first-child) selector, you remove that problem. You can use this selector on every HTML element. Another common use case is if you use an unordered list <ul> for your menu.


1 Answers

#mytable th:last-child, #mytable th:first-child {
 //css goes here
}
like image 156
Codler Avatar answered Oct 19 '22 20:10

Codler