Solved

CSS - show list style on hover

Posted on 2009-07-02
7
1,164 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now