Forum Moderators: not2easy

Message Too Old, No Replies

CSS to highlight current link

list background not appearing in IE

         

zarastudios

8:49 pm on Aug 8, 2005 (gmt 0)

10+ Year Member



I want to use CSS to highlight the current link on my menu, and the following works great in all browsers except IE 6, where nothing happens. Any ideas about why this might be happening? Thanks.

<ul>
<li id="one"><a href="#">link</a></li>
<li id="two"><a href="#">link</a></li>
<li id="three"><a href="#">link</a></li>
</ul>

#page_one #one{
background:red;
font-weight:bold;
}
#page_two #two{
background:red;
font-weight:bold;
}
#page_three #three{
background:red;
font-weight:bold;
}

SuzyUK

9:05 am on Aug 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi zarastudios

I'm assuming that the id's #page_one, #page_two, and #page_three are set on the body element of the pages?

if so this code snippet is working in IE6 for me.. but I believe you and suspect that there may be more styling of this <ul> and these links involved and that there is an IE Layout "bug" going on here..

to toubleshooot: validate your HTML [validator.w3.org] and CSS [jigsaw.w3.org] in case there could be some malformed markup causing the confusion?

then if it's still present try adding

{zoom: 1;}
first to the <ul> (my favourite choice), then to the <li> then to the <a>, but only one at a time see if any help, it might not.. I'm just guessing

if it does give us a shout back with which one worked, and if you don't want to use "zoom" to fix it it's microsoft proprietary and will not validate and it only works in IE5.5+

if not then can you post the whole code (HTML and CSS) for this list, and it's containing div (if there is one)

There is a known issue about disappearing list backgrounds, but the solution of putting

position: relative;
onto all lists is IMHO a bit risky as using position:relative; without applying "layout" can cause other (IE) issues.

see how it goes and let us know

Suzy

zarastudios

3:04 pm on Aug 9, 2005 (gmt 0)

10+ Year Member



Hi. I tried using zoom: 1; and now the background is showing up, but the rest of the links are in the wrong place. Is there a way around using the zoom property? Here's my code:

The menu is placed inside a div called links, which is inside a div called menu.
#menu {
width: 700px;
background: #000040;
text-align: left;
height: 30px;
}
#links {
float: left;
width: 426px;
padding-left: 6px;
font-size: 1.1em;
font-weight: bold;
line-height: 1.5em;
}
#nav li {
display: inline;
list-style-type: none;
}
#nav a:link, #nav a:visited, #nav a:active {
color: #208639;
text-decoration: none;
padding: 4px 4px 11px 4px;
}
#nav a:hover {
color: #6f9fdf;
}

Every page has a different body id, below is an example:

#page_home #home {
background: url(images/pointer.gif) no-repeat center 100%;
color: #6f9fdf;
padding-bottom: 11px;
}

The markup for the list is:

<ul id="nav">
<li id="home">
<a href="?page_id=2">HOME</a>
</li>
<li id="about">
<a href="?page_id=3">ABOUT</a>
</li>
<li id="services">
<a href="?page_id=4">SERVICES</a>
</li>
<li id="resources">
<a href="?page_id=5">RESOURCES</a>
</li>
<li id="faqs">
<a href="?page_id=6">FAQS</a>
</li>
<li id="contact">
<a href="?page_id=7">CONTACT</a>
</li>
</ul>

Thanks for your help.

SuzyUK

4:26 pm on Aug 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi. I tried using zoom: 1; and now the background is showing up, but the rest of the links are in the wrong place. Is there a way around using the zoom property?

Yes there's a way around using it, but which element did you set it on that made the background come back? I still can't recreate the disappearing act :o

and now seeing that the list is created by making the <li>'s display inline, I'm not so sure the other cure (which is to set a width or height onto the affected element for IE Only) will work either as you can't set a width/height on an inline element..

Here's the code I've got where I can see the background (I added the red) I'm putting it out for checking because it doesn't look the same in other browsers so I want to check we're on same code..

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /></meta>
<title>Untitled</title>
<style type="text/css" media="screen">
#menu {
width: 700px;
background: #000040;
text-align: left;
height: 30px;
}

#links {
float: left;
width: 426px;
padding-left: 6px;
font-size: 1.1em;
font-weight: bold;
line-height: 1.5em;
}

#nav li {display: inline;}

#nav a:link, #nav a:visited, #nav a:active {
color: #208639;
text-decoration: none;
padding: 4px 4px 11px 4px;
}
#nav a:hover {
color: #6f9fdf;
}

#page_home #home {
background: #f00 url(images/pointer.gif) no-repeat center 100%;
color: #6f9fdf;
padding-bottom: 11px;
}
</style>
</head>
<body id="page_home">
<div id="menu">
<div id="links">
<ul id="nav">
<li id="home"><a href="?page_id=2">HOME</a></li>
<li id="about"><a href="?page_id=3">ABOUT</a></li>
<li id="services"><a href="?page_id=4">SERVICES</a></li>
<li id="resources"><a href="?page_id=5">RESOURCES</a></li>
<li id="faqs"><a href="?page_id=6">FAQS</a></li>
<li id="contact"><a href="?page_id=7">CONTACT</a></li>
</ul>
</div>
</div>
</body>
</html>

Suzy

zarastudios

5:57 pm on Aug 9, 2005 (gmt 0)

10+ Year Member



Hi. I added the zoom property to the <li>. When I tried the code you used, I had no problems seeing the red either. The image just isn't showing up for some reason.