Reputation: 347
I have small generic table which looks something like this:
<table>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
</tr>
</table>
I want to be able to click on each table data to expand additional information. Can I do this using only css or do I have to resort to javascript?
Upvotes: 1
Views: 5997
Reputation: 1160
I don't think you can achieve this with css.
But with jQuery's slideToggle()
, it's a piece of cake!
Upvotes: 2
Reputation: 72261
You probably will want javascript (and definitely will if you intend the item to stay open after being clicked). But to demonstrate there are instances where it can be done purely with CSS, this will work in CSS3 browsers (only while holding down the mouse button).
HTML
<table>
<tr>
<td>1<div>More info on 1</div></td>
<td>2<div>More info on 2</div></td>
</tr>
<tr>
<td>1<div>More info on 1</div></td>
<td>2<div>More info on 2</div></td>
</tr>
</table>
CSS
td {
vertical-align: top;
}
td > div {
height: 0;
overflow: hidden;
}
td:active > div {
height: auto;
}
Upvotes: 2