Position:Absolute Bottom:0 not working when adding a height

Hi all,

Hoping someone can help me or tell me I’m being stupid!

I have my navigation set up for the site I’m working on as an unordered list of inline links.

I’m trying to get it so I have the text of each listitem fixed to the bottom of the list and then when I rollover each listitem, the a:hover displays an image as a rollover effect using CSS sprites.

If I use position:relative on the UL and then position:absolute; bottom:0; it works fine UNTIL I add a height for the anchor tag.

As soon I add a height to the anchor tag it ignores the position absolute and puts the text of the link at the top of the area. Is this correct?

I need to set a height for the anchor tag so the a:hover has a height for the rollover effect.

Thanks for reading

Hi scottjack. Welcome to SitePoint. :slight_smile:

It would be much better if you could show us a live link. If you are using sprites, the normal state could just have the text at the bottom and the hover state have the text in a different spot. So this should be easy. But we eed to see what you are doing. :slight_smile:

Hi Ralph,

Here is the in progress site link.

http://edtaylordesign.co.uk.temp-www5.com/

So for the navigation at the top I would prefer it to have the text below the images. I obviously would need to change the sprite so that the whitespace is below the image so the text can sit in the whitespace.

I want to do this with text and images, rather than just adding text into the image as such.

This is the link to the sprite.

http://edtaylordesign.co.uk.temp-www5.com/files/images/navigationbar.jpg

Thanks

Unfortunately, I’m not getting a clear idea of what you want to see here. From the sound of it, these are not technically ‘sprites’. But anyhow, I can’t quite picture what you are expecting this to look like. Could you elaborate?

I’ve added a background colour to the area so you can see a bit more clearly. I want the text at the bottom of the red area, which I can achieve with position:absolute, bottom:0 but as soon as I add a height to the A tag that each section is, the text goes to the top.

Thanks

This is my current relevant CSS

.navHome a, .navContinuum a, .navQube a, .navSigma a, .navETGuitars a, .navBlog a, .navAbout a, .navContact a
{
width:88px;
height:106px;
display:inline-block;
text-decoration:none;
background-color:Red;
}

and then the hover states for each section

.navHome a:hover { background-image:url(‘images/navigationBar.jpg’); background-repeat:no-repeat; background-position:0px 0px; text-decoration:underline; }

.navContinuum a:hover { background-image:url(‘images/navigationBar.jpg’); background-repeat:no-repeat; background-position:-88px 0px; text-decoration:underline; }

etc… (Each section moves along 88px to the next image in the “sprite” (Why technically aren’t these sprites?)

Thanks

What you could do is reduce the height of the <a>s and add top padding instead:

.navHome a, .navContinuum a, .navQube a, .navSigma a, .navETGuitars a, .navBlog a, .navAbout a, .navContact a {
  background-color: Red;
  display: inline-block;
  [COLOR="#FF0000"]height: 26px;
  padding-top: 80px;[/COLOR]
  text-decoration: none;
  width: 88px;
}

Then remove the top whitespace on the sprite image and the images will appear at the top of the link on hover. The sprite image is 106 px tall, so the icons can’t help but appear at the bottom of the anchor. Cut off the top of the image and make it, say, 80 px tall, and you will get your effect.

Fantastic!!

That’s sorted it. I could not work that out at all! Thank for your help.

Great! One extra thing that might be nice is to have the image appear when the page is current, to make it clear what page one is on. It’s quite easy to do that with CSS. One way to do it is to add a unique class to the body tag of each section. So, on the Qube page, add something like

<body class=“qube”>

and then add this to the CSS:

[COLOR="#FF0000"].qube .navQube a[/COLOR], .navQube a:hover {
  background-image: url("images/navigationBar.jpg");
  background-position: -176px 0;
  background-repeat: no-repeat;
  text-decoration: underline;
}

Yes I agree, I’ve done that on other sites and intend to do it on this one as well.

Can I ask why these technically arern’t sprites? My understanding of sprites is using one image file and selecting your images from it using background position?

:slight_smile:

Sorry, forget that comment. I’m used to sprites having a hover and non-hver state, but didn’t realize you were using one big image.