I want to add a logo hyper-link to the top left of my header, but my header has text-align:centre to centre the title of the page making anything I try very awkward
This is what I currently have, and it almost works but the image sticks out the top of the header. Changing the ‘top: 0;’ value makes it jump far down the header rather than moving it slightly.
<header>
<h1>Homepage</h1>
<style type="text/css">
#topleft {
position: absolute;
left: 10;
top: 0;
display: block;
height: 140px;
width: 140px;
background: url(images/DSC_0416-1.jpg) no-repeat;
text-indent: -999em;
text-decoration: none;
}
</style>
<a id="topleft" href="index.html" title="TopLeft">Top Left Link Text</a>
</div>
2
Answers
You need to restructure your layout. I will suggest you use semantic html and apply css accordingly.
Hope this helps.
At the moment it looks as though the header element hasn’t been given any positioning.
This means the system will default to placing the absolute positioned image relative to the nearest ancestor that does have a position set – probably body in your case as a header element is likely to be quite far up the tree.
This snippet gives the header element position relative.
Note: the image has been given a linear gradient image just for this demo. Also it has been placed centrally vertically in the header element. Remove if not wanted. You may actually be wanting to give the header some height so the positioning of the top of the image can be exactly where you want it. This snippet moves the header down a bit to show the effect of the absolute positioning – another thing to remove if not wanted of course.