Solved

CSS - show list style on hover

Posted on 2009-07-02
7
1,179 Views
Last Modified: 2012-08-13
Hello,

I've been banging my head against the wall on this one. All I'm trying to do is display the list style (i.e. disc) when someone hovers over a link in an unordered list. The list style should be hidden by default and only be displayed when someone hovers over a link. Attached is the code.

thanks
<!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=utf-8" />
<title>Untitled Document</title>
<style>
li a {
 
	list-style-type:none;
	list-style:none;
	text-decoration:underline;
	display:block;
 
}
 
li a:hover {
 
	list-style-type:disc;
	text-decoration:none;
 
}
</style>
</head>
 
<body>
<ul>
  <li><a href="#">A</a>
    <ul>
      <li><a href="#">1</a></li>
      <li><a href="#">2</a></li>
      <li><a href="#">3</a></li>
    </ul>
  </li>
  <li><a href="#">B</a></li>
  <li><a href="#">C</a> </li>
</ul>
</body>
</html>

Open in new window

0
Comment
Question by:wattanabi2
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 7

Accepted Solution

by:
szewkam earned 500 total points
ID: 24768314
Try something like this in snippet. Works in FF3 and Opera9.
ul {
 
        list-style-type:none;
        list-style:none; 
        display:block;
 
}
a { display: block;}
li:hover, a:hover {
        list-style-type:disc;
        text-decoration:none;
 
}

Open in new window

0
 
LVL 10

Expert Comment

by:mstrelan
ID: 24770246
list-style-type only applies to <li> elements not to <a>s
in internet explorer less than 8 you can only apply :hover to <a> elements, not to <li>
so you have three options

1. ignore ie6 and 7
2. produce invalid markup by wrapping <a>'s around the <li>'s and apply a:hover li { }
3. use a javascript solution..
li.onmouseover = function() { this.className = 'bulleted'; }
li.onmouseout = function() { this.className = ''; }
// and use a css class called .bulleted instead of :hover
0
 
LVL 42

Expert Comment

by:David S.
ID: 24770267
IE7 supports :hover on most elements. It's versions before it that have very limited support for it. (http://reference.sitepoint.com/css/pseudoclass-hover)

There's a better option for making it work in IE6: http://www.xs4all.nl/~peterned/csshover.html
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 10

Expert Comment

by:mstrelan
ID: 24770316
this is why kravimir is a genius and i am a nothing :)
0
 

Author Comment

by:wattanabi2
ID: 24772687
The code that szewkam provided seems to do the trick. I've gone from:

list-style-type:disc;

to

list-style-image:url(http://cache-foo.gawker.com/gawker/assets/base.v8/img/icons/flame.png);

Using an image instead of a list-style-type. Works fine in FF but in IE7, when hovering over one of the ul li items (1,2,3), all three items display the image instead of just the one that I'm hovering over.

Thoughts?
<!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=utf-8" />
<title>Untitled Document</title>
<style>
ul {
 
        list-style-type:none;
        list-style:none; 
        display:block;
 
}
 
a { 
 
		display: block;
}
li:hover, a:hover {
 
        /* list-style-type:disc; */
		list-style-image:url(http://cache-foo.gawker.com/gawker/assets/base.v8/img/icons/flame.png);
        text-decoration:none;
 
}
</style>
</head>
 
<body>
<ul>
  <li><a href="#">A</a>
    <ul>
      <li><a href="#">1</a></li>
      <li><a href="#">2</a></li>
      <li><a href="#">3</a></li>
    </ul>
  </li>
  <li><a href="#">B</a></li>
  <li><a href="#">C</a> </li>
</ul>
</body>
</html>

Open in new window

0
 
LVL 7

Expert Comment

by:szewkam
ID: 24772743
i'm afraid that you have to wait for somebody who has windows with ie ;). I can't help with it, I successfully get rid of ie :)
0
 
LVL 42

Expert Comment

by:David S.
ID: 24773963
Instead of

list-style-image:url(http://cache-foo.gawker.com/gawker/assets/base.v8/img/icons/flame.png);

I suggest you use

background: url(http://cache-foo.gawker.com/gawker/assets/base.v8/img/icons/flame.png) no-repeat left center;
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question