Alt-Web Design & Publishing
CSS Clickable Table Cells
Description:
Sometimes it's nice to have an entire table cell behave like an active link or button. Unfortunately HTML doesn't allow <td> tags to be inside anchors. When used, anchors need to be inside <td> tags. Now with the magic of CSS, we can style table cells and the anchor tags inside them to work as a single unit.Example:
| Mouseover or use your Tab key to highlight cells below | ||
|---|---|---|
Method:
I built this table with a product catalog in mind so my CSS selector name (.prod) reflects this. You can change the code to use any selector name you wish.
CSS2 Code
table.prod {
width: 600px;
border-collapse:collapse; border:none;
}
.prod a img {
border:none;
float:left;
padding-right:12px;
}
.prod td {
width:200px;
border: 1px solid #000
}
.prod td p {
margin:0;
line-height: 1.2em;
font-size: 16px;
}
/**here's the magic part**/
.prod td a {
display:block;
height:7em; /**adjust height in ems as required**/
text-decoration:none;
}
/**link states**/
.prod td a:link {color: #000}
.prod td a:visited {color:#666}
.prod td a:hover, .prod td a:active,
.prod td a:focus {
background-color:#CCFF00
}
Earn money from your website with
Lunarpages Affiliate Program.
HTML Code
<table class="prod" cellspacing="0" cellpadding="0">
<tr>
<td><p><a href="#"><img src="your-image.png"/>Some
link text goes here</a></p></td>
<td><p><a href="#"><img src="your-image.png"/>Some
link text goes here</a></p></td>
<td><p><a href="#"><img src="your-image.png"/>Some
link text goes here</a></p></td>
</tr>
<tr>
<td><p><a href="#">Some link</a></p></td>
<td><p><a href="#">Some link</a></p></td>
<td><p><a href="#">Some link</a></p></td>
</tr>
</table>
Demos:
- Photoshop Tutorial - Box with Contoured Edges
- Bringing Image Slices into a CSS Layout
- CSS Disjointed Text Rollovers
- CSS Disjointed Menu Rollover
- Floats & Margins, 3 CSS Boxes
- CSS Menus
- CSS Sprites Demo I
- CSS Sprites Demo II
- CSS2 Captions on Floated Images
- CSS2 Sticky Text
- CSS3 Multi-Backgrounds
- Fixed Background Image
- Liquid Header
- Multi-Scrollbars
CSS Templates:
- Centered, Fixed-Width page with floats
- Centered, Liquid-Width page with floats
- I-Page, Liquid Header & Footer
- 1 Column, Fixed-Width Centered
- Faux Column, Fixed-Width Centered
- Right Column, Fixed-Width Centered
- 3 Column, Fixed-Width Centered
- 3 Column, Liquid Layout
- User Adjustable Page
- Horizontal & Vertical Centered
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Lorem
ipsum dolor sit amet, consectetur adipiscing elit.