Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ways to hide first column of table through CSS

Tags:

html

css

This code is working on browsers other than IE:

table.tbl.tr.td:first-child { display: none; }

What shall I use for to make it work on all browsers?

like image 601
RKh Avatar asked Dec 08 '09 13:12

RKh


People also ask

How do you hide a table column in CSS?

Usually, to hide an element from view, you use the 'display' property and set it to 'none'. But CSS also has a property called 'visibility', which hides elements in a different way. In particular, we use 'visibility: collapse' here, which is designed especially for hiding table columns and rows.

How do I hide one column in html?

To hide a column entirely from view, meaning it will not be displayed in either the normal or details row, simply use the visible column option and set it to false . This example shows a table where the first column ID is completely hidden from view using the data-visible column attribute.

How do you select the first column of a table in CSS?

The syntax is :nth-child(an+b), where you replace a and b by numbers of your choice. For instance, :nth-child(3n+1) selects the 1st, 4th, 7th etc. child.


2 Answers

Your expression above won't work at all. table.tbl.tr.td will select a table element that is defined like this: <table class="tbl tr td"> but not its cells.

It should be like this and the :first-child selector is supported in pretty much all browsers above Internet Explorer 6:

table.tbl tr td:first-child { display: none; }
like image 199
poke Avatar answered Sep 18 '22 09:09

poke


Unfortunately, older versions of IE do not support :first-child in CSS. Don't know about IE8. Anyways, if you don't want to do javascript, and you have access to the html, it's pretty easy to assign a "first" class to the first column tds in the table. So the html will look like:

<table>
  <tr>
    <td class="first">...</td>
    <td>..</td>
    ..
  </tr>
</table>

You can then create a css entry like:

table td.first { display: none; }
like image 28
Linus Avatar answered Sep 19 '22 09:09

Linus