|
|||||||
New to SitePoint Forums? Register here for free!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
SitePoint Member
Join Date: May 2009
Posts: 8
|
Inline image rollover being cut off
Hi, I'm a newbie and just learning CSS and web design.
I have a horizontal navigation bar, and I want an image to appear above each link on the hover and active states. The image is being cut off on the top, and my attempts to position it haven't worked, even though there is an inline image that is the same height as the clipped image that isn't cut off. Any help greatly appreciated!! I tried posting the link, but this is my first post, and Sitepoint won't let me. Here is the CSS - I'll try attaching the HTML: CSS Code:
Last edited by AutisticCuckoo; Aug 3, 2009 at 12:20. Reason: Added syntax highlighting for easier reading |
|
|
|
|
|
#2 |
|
SitePoint Member
Join Date: May 2009
Posts: 8
|
I've gotten a little bit closer to what I want! I added a class selector and an empty span element to the <a> element. Now I see my image over each link when I hover (in FF and Opera, something goofy in Safari, and haven't checked IE yet). Next issue to tackle:I'd like the image centered over each link, and right now I have it absolutely positioned in the top left corner above each link.
How do I center the image over each text link? Here is that section's CSS: CSS Code:
Thanks for any help! I have three books open on my lap, and have been searching online for a week to try to figure this out! Last edited by AutisticCuckoo; Aug 3, 2009 at 12:21. Reason: Added syntax highlighting for easier reading |
|
|
|
|
|
#3 |
|
SitePoint Wizard
![]() ![]() Join Date: Nov 2004
Location: Åsnorrbodarna
Posts: 11,777
|
I've added some syntax highlighting and I'm moving the thread to the CSS forum where the gurus roam.
![]() |
|
|
|
|
|
#4 |
|
CSS Consultant/Ninja-I'm fast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Oct 2008
Location: Whiteford, MD
Posts: 10,074
|
Hi, which element in the CSS do you wnat centered that is AP'd? There arae quite a few. Also you can post a link by leaving off the http://www. parts of the URL so it looks like this
sitehere . com / page . php Also you should know that setting z-index only applies to element that have position set, aka relative, absolute, or fixed. Overflow:visible is the default value and setting it does nothing special other then resetting it if it was previously set Also note that if you are going to use AP then it is best to set both coordinates as IE needs both set otherwise factors such as text align will influence the position. And also note that setting display:inline; on an element such as a <li>, or any other element like that will cause it to ignore widths/heights, if you need to accesss these properties you can set display:inline-block though be aware FF2 andn Ie6/7 need work (floating would be a good alternative if possible) FF2 needs display:-moz-inline-block; set (before inline-blockk is fed to good browsers) and then IE6/7 need a CC set for them to set display:inlline; for them because otherwise it won't recognize inline-block because they only recognize inline-block for inline elements by nature. That should set you off ![]() |
|
|
|
|
|
#5 |
|
SitePoint Member
Join Date: May 2009
Posts: 8
|
Thanks!! I will try some of these suggestions. The test site is up at thrownawaycircus dot com slash StanleyTest.
The element I would like centered is the .imgtip over the inline navigation links in the hover and active states. I'd like it centered over each nav link, but as the links are live text, there isn't a set width to them - Some are wider and some are narrower based on the text, and the font size is variable based on browser interpretation. It's not a deal-breaker - I could live with the image lining up at the top left corner above each link as it is now, but if there's a way to center it, I'd love to learn! I have cleaned up some of the CSS, but still have more to do. Just getting my feet wet in CSS (print designer stepping into web) and trying to see what works and what doesn't and why. It passes validation, but I don't want useless matter in there. Other than centering that particular element, the site looks fine in FF, Safari, Opera, Chrome and IE 8. The .imgtip is up too high in IE7, and I haven't braved an IE6 viewing yet... |
|
|
|
|
|
#6 |
|
CSS Consultant/Ninja-I'm fast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Oct 2008
Location: Whiteford, MD
Posts: 10,074
|
Hi, I think this can be achieved by doing something like this, note that for perfection an extra element is needed
Have your HTML like this Code:
<li><a href="prevention.html" class="imgtipped">Breast Cancer Prevention<span class="sexy"><span class="imgtip"></span></span</a></li> Code:
.imgtipped:hover span.sexy
{
position:absolute;
left:50%;
top:-1em;
display:block;
width:27px;
height:15px;
}
.imgtipped:hover span.sexy .imgtip {
position: absolute;
left: -50%;
display:block;
top: 0;
width: 27px;
height: 15px;
background-image: url(images/leaf.png);
background-repeat: no-repeat;
z-index: 5;
}
|
|
|
|
|
|
#7 |
|
SitePoint Member
Join Date: May 2009
Posts: 8
|
Brilliant! Thanks! So I needed more containers, basically - there wasn't anything to position the image relative to - is that right? Any explanation will be appreciated.
Another question: how do I get the image to remain on when you're on a certain page? I thought the active state did that. Do I need another class for the li selector? (Sorry if I'm mashing terms, I'm a beginner!) I'm trying this, but the image appears only to the left of the link: li.current_page { position: relative; } li.current_page .imgtip { position: absolute; left: 50%; display: block; top: 0; width: 27px; height: 15px; background-image: url(images/leaf.png); background-repeat: no-repeat; z-index: 5; } li.current_page { position: relative; } li.current_page span.bright .imgtip { position: absolute; left: -50%; display: block; top: 0; width: 27px; height: 15px; background-image: url(images/leaf.png); background-repeat: no-repeat; z-index: 5; } |
|
|
|
|
|
#8 | ||
|
CSS Consultant/Ninja-I'm fast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Oct 2008
Location: Whiteford, MD
Posts: 10,074
|
Quote:
Quote:
|
||
|
|
|
|
|
#9 |
|
SitePoint Member
Join Date: May 2009
Posts: 8
|
Thanks Ryan, for the helpful comments and explanation with this. I got the image to stay on for the current page with a new class too. On to IE fixes and cleaning up the CSS!
a.current { position: relative; text-decoration: none; cursor: default; } a.current span.bright { position: absolute; left: 50%; top: -1em; display: block; width: 27px; height: 15px; text-decoration: none; cursor: default; } a.current span.bright .imgtip { position: absolute; left: -50%; display: block; top: 0; width: 27px; height: 15px; cursor: default; text-decoration: none; background-image: url(images/leaf.png); background-repeat: no-repeat; z-index: 5; } |
|
|
|
|
|
#10 |
|
CSS Consultant/Ninja-I'm fast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Oct 2008
Location: Whiteford, MD
Posts: 10,074
|
Looks good
. Your welcome. |
|
|
|
|
|
#11 |
|
SitePoint Member
Join Date: May 2009
Posts: 8
|
Just wanted to update for anyone else trying to do the same thing: While trying to fix for IE 6 and 7, I found (with help!) another way to have an image appear over the links in the horizontal navigation, and have that image remain when you're on a current page. Instead of the CSS for the nested span elements, I added a display:block for the a element in the li, and grouped the CSS for the hover, active and current classes. Some finagling with this method also cleared up the problems I was having in IE, without any conditional comments. Yay!
[COLOR="rgb(255, 0, 255)"]#navigation[/color] { background: #fff; text-align: center; height: 80px; padding: 0; margin: 0 0 0 80px; } [COLOR="rgb(255, 0, 255)"]#navigation[/color] ul { margin: 0; padding: 0; background-color: #fff; position: relative; height: 41px; } [COLOR="rgb(255, 0, 255)"]#navigation[/color] li { display: inline; font-size: .9em; list-style-type: none; color: #cc3366; float: left; padding: 0 1.5em 0 0; margin: 0; height: 41px; position: relative; } [COLOR="rgb(255, 0, 255)"]#navigation[/color] li a { display: block; } .imgtipped { padding-top: 18px; margin-top: 10px; font-size: 13px; } .imgtipped:hover, .imgtipped:active, a.current { background-image: url(images/leaf.png); background-repeat: no-repeat; background-position: top center; } a.current { text-decoration: none; cursor: default; } |
|
|
|
|
|
#12 |
|
SitePoint Member
Join Date: May 2009
Posts: 8
|
oops - sorry, my color coding didn't work too well there!
![]() |
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
|
All times are GMT -7. The time now is 16:25.














Hybrid Mode
