How can I make my css sprite back button validate through W3C? Here is my code to call the button.
<a href="#" onclick="history.go(-1)"><div class="icon-backbtn"></div></a>
How can I make my css sprite back button validate through W3C? Here is my code to call the button.
<a href="#" onclick="history.go(-1)"><div class="icon-backbtn"></div></a>
I ended up using the below code to pass W3C validation and still using CSS Sprites.
<a id="icon-backbtn" title="Back" href="#" onclick="history.go(-1)"></a>
You shouldn't have a <div>
as a child of an <a>
, use an <img src="..."/>
instead.
EDIT:
If you have a spritesheet, then simply add display:block;
for the anchor and it will behave just like a div.
Since you are using a CSS Sprite, I would suggest placing the <a>
inside the <div>
(proper way to do it) and add some css:
HTML
<div class="icon-backbtn">
<a href="javascript:history.go(-1)" title="Go Back"></a>
</div>
CSS
.icon-backbtn a {
display:block;
cursor:pointer;
text-decoration:none;
text-indent:-9999px;
}
The CSS sets the link to be a block element, thus occupying the width and height of the div. The remaining styles are to prevent the regular link behavior for texts, since you are using an image.