views:

212

answers:

3

We have an anchor tag floating right inside a header issue. It works fine on IE8 and Firefox.

Any idea how to stop it popping outside the header box?

Here is the code below:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html>
<head>
<style>
 .wrapper { border: 1px solid black; }
 .wrapper h3 a { float: right; }
</style>
</head>
<body>
<div class="wrapper">

<h3>Contact Details
 <a href="#" class="action button">Update</a>
</h3>
</div>
</body>
</html>
A: 

If you are floating it you need to tell the h3 to clear it. I assume this would work:

.wrapper h3 { overflow:hidden; zoom:1; }

LMK if not. And FYI, I wouldn't put the anchor inside of the h3 like that. I would probably make it a sibling of the h3, if necessary wrap a div around both and then apply the overflow/zoom.

meder
This does stop it popping out of the box, but the header is pushed to the top of the box and the link pushed to the bottom.
lawardy
Are you hiding some CSS? Can you provide a demo?
meder
A: 

Fixed it. Here are two extra rules that I added in

.wrapper h3 { overflow:hidden; zoom:1; } 
.wrapper h3 a { margin: -1em 0 0 0; }
lawardy
+2  A: 

Put the right floated element first.

<h3><a href="#" class="action button">Update</a>Contact Details</h3>
Emily
I wish there was a more elegant solution, but this does resolve the problem. See example - http://jsfiddle.net/h5Zmu/4/
Jason McCreary