Seems your structure isn’t quite correct: you have block level (div) nested inside inline (a tag). You might rethink that structure
If you still have problems, post the full html and css code or a link to a live page (because you’re new, you wont be allowed yet to post the link in it’s normal way, so just replace the dots in the adress with the word ‘dot’. We’ll do the rest )
Well, Firefox is being kind to you with your errors. The HTML5 people did decide to change the rules and let anchors wrap divs… so if you wanted to research HTML5 and switch to that then possibly all the browsers would be cool with that, I dunno.
However, remaining in the real world of HTML4, you would have to do one of two things (because I’m pretty sure your problem with IE8 is IE is actually calling you out on your error… removing the error should make it work):
You can either change all those divs to some legal inline element (spans are fine for this) and if they need block nature, with css you can set the to display: block;
Or, you can have divs on the outside and anchors on the inside and those anchors themselves set to display: block (so they can have a set height and width).
I’m leaning towards #1 because that preserves most of what you already have. Remember that this means your p’s also have to change to something inline.
Blocks are like buckets. Inlines are like water. Buckets can hold water, and other buckets, but water can’t hold a bucket.
Here you go: you have some validation errors, mainly because you nested block elements into an inline element, like i already told you. IE6 and Opera choked on that
I didn’t take a close look at your css or didn’t alter much to your structure. Like poes said, there are some ways to go round but i took the easy way out (being the lazy bum i am lol) and cleaned up your nesting structure. I also removed the extra closing body tag. See if this works for you (only tested locally in Opera and IE6):
You can fake this by overlaying an absolute anchor
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>YuriKolovsky - overlay layers in IE6</title>
<style type="text/css">
/*this is organised for you*/
/*Predefined Vars*/
* {
margin:0;
padding:0;
}
.hoverb {
position:relative;
margin-top:1.25em;
margin-left:1.25em;
}
/*Predefined Vars*/
/*width / height*/
.hoverb div, a, a:hover span {
border-style:solid;
border-width:4px;
}
.hoverb div, a, a span {
width:12em;
height:100px;
}
a {
display:block;
margin-top:-108px;
text-decoration:none;
}
h2, p {
width:12em;
margin:4px;
}
/*width / height*/
/*overlay trickery*/
a span {
display:block;
position:absolute;
z-index:10;
top:0px;
left:0px;
background-image:url(fake.gif);
cursor:pointer;
}
h2, p {
position:absolute;
left:0;
z-index:2;
}
/*overlay trickery*/
/*Colors*/
.hoverb div {
background-color:#999;
}
a {
border-color:#555;
}
a:hover {
background-color:#e3e3e3;
}
a:hover span {
border-color:#000;
}
/*Colors*/
/*MISC*/
h2 {
margin-top:-1px;
margin-left:10px;
font-size:xx-large;
}
p {
margin-left:10px;
margin-top:8px;
top:1.7em;
font-size:large;
}
/*MISC*/
</style>
</head>
<body>
<!--having h2 and p to look like its inside a link can be usefull, as clients often want hover buttons with text, and usually use ie6...
notice how the links are clickable-->
<div class="hoverb">
<div><h2>Planes</h2><p>for air travel</p></div><!--you could probably put all this in another div and treat that div as the h2 and p, and move h2, p inside the div-->
<a href="#planes"><span> </span></a><!-- is to avoid the empty span warning in the validator-->
</div>
<div class="hoverb">
<div><h2>Trains</h2><p>for land travel</p></div>
<a href="#trains"><span> </span></a>
</div>
<div class="hoverb">
<div><h2>Automobiles</h2><p>for personal travel</p></div>
<a href="#automobiles"><span> </span></a>
</div>
</body>
</html>
if you replace every div and p with a span, that will make it legal but as I said, they are inlines and so to make them act like the divs did, you need to make them display: block in the css. You didn’t have to say that for the divs or the ps because that’s how they come out of the box.
That way a single anchor can remain a parent for the other elements.
That’s not what im trying to do. That makes the text have a white background when hovered, but im trying to make the whole div white when hovered like it does for me in firefox,
I understand this is not possable to wrap a a href arounf a div, but is there a way i can get the effect i want in ie using someother tag?
Im still just learning css so examples are a great help.
Both at the same time? I don’t think that would be possible without some javascript in place :). Because if you think about it, you can’t hover over two elements at once, nor can you make that kinda shape with an element (an anchor is inline and it wrapped around the <div> in your first example to create taht shape. Other browsers won’t do that)