Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS for first td of each tr in certain table

Tags:

html

css

I have table with id "student". e.g.

 <table id="student">     <tr>         <td>Role</td>         <td>Merin</td>         <td>Nakarmi</td>     </tr>     <tr>         <td>Role</td>         <td>Tchelen</td>         <td>Lilian</td>     </tr>     <tr>         <td>Role</td>         <td>Suraj</td>         <td>Shrestha</td>     </tr> </table> 

For each row in this table, the first <td> has value Role and I want to hide this first <td> for every row. I tried option like

#student > tr > td:first-child {      width: 0px; important; } 

But unfortunately did not work.

Please help

like image 639
Merin Nakarmi Avatar asked Nov 19 '13 09:11

Merin Nakarmi


People also ask

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 I select the first TR in CSS?

With <tr> tag In this CSS :first-child example, the first row (ie: the first <tr> tag) will have a yellow background color. All other rows in the table will not be styled by the :first-child selector.

How do I select a specific TD in CSS?

This can be achieved using :nth-of-type() instead of :nth-child() , as the former only considers elements of the same type when calculating their indices. Note though that both :nth-child() and :nth-of-type() are only supported in IE9 and above.

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.


2 Answers

Use the below.

table#student tr td:first-child{display:none;} 

WORKING DEMO

like image 112
Nitesh Avatar answered Oct 02 '22 20:10

Nitesh


Your this code is not correct:

{ width: 0px; important; } 

this should be:

#student > tr > td:first-child{    width: 0px !important;  } 

before important property you are using semicolon which is not correct.

like image 22
Code Lღver Avatar answered Oct 02 '22 18:10

Code Lღver