Solved

CSS - show list style on hover

Posted on 2009-07-02
7
1,184 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
alert(innerHTML); 8 32
styling bootstrap grid system with CSS 2 38
Troubles viewing HTML in Outlook 2010 client 3 29
Media Queries  not Firing 6 17
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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 code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

839 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