Kindly go through this link and notice the solution given by "thepeer": https://stackoverflow.com/a/3494108
I am having trouble understanding his solution. Let me illustrate with the example of a webpage that I am trying to build. I am using HTML5 to build "buttons". Now since these buttons are actually DIV objects, I somehow need to make them "clickable" which would lead the viewer to another page, and that too, without making the "link" visible. The div object should act as a button and I don't intend to "include" a hypertext-ed line of text inside the button.
I think the solution given by "thepeer" does exactly that but i am unable to understand his solution and implement it. Perhaps a very small example would benefit me.
Suppose this is the button that i want to make :
<div id="music" class="nav">Music I Like <span id="hyperspan"><a href="Music.html"></a></span></div>
And here's the CSS as "thepeer" suggested :
.hyperspan
{
position:absolute;
width:100%;
height:100%;
left:0;
top:0;
z-index:1;
}
Now, obviously, I misunderstood his solution and hence my above attempt is incorrect. I don't want to resort to javascript so please help me! Sorry for my noobish-ness.
Just use an <a>
by itself, set it to display: block;
and set width
and height
. Get rid of the <span>
and <div>
. This is the semantic way to do it. There is no need to wrap things in <divs>
(or any element) for layout. That is what CSS is for.
Demo: http://jsfiddle.net/ThinkingStiff/89Enq/
HTML:
<a id="music" href="Music.html">Music I Like</a>
CSS:
#music {
background-color: black;
color: white;
display: block;
height: 40px;
line-height: 40px;
text-decoration: none;
width: 100px;
text-align: center;
}
Output:
Source: Stackoverflow.com