2013-10-12 31 views
1

这是一个奇怪的问题,但我得到了一个html文件,它具有标签的B标签和列表的单独ol标签。CSS - 在元素E2上悬停时显示元素E1

像这样

<b> Title of the list </b> 
<ol> 
    <li> List item 1 </li> 
    <li> list item 2 </li> 
</ol> 

我希望做的是,节目列表,当鼠标悬停称号。我该怎么做呢?

现在这就是我所拥有的。

ol 
{ 
    visibility: none; 
} 

我需要找到这部分

b:hover 
{ 
    /*something that shows the ol list */ 
} 
+0

是否确定要使用'visibility'了'display' ? –

+0

可能重复[如何更改一个元素,而徘徊在另一个](http://stackoverflow.com/questions/8614423/how-to-change-one-element-while-hovering-over-another) – Pavlo

回答

2

使用此代码:

HTML:

<b> Title of the list </b> 
<ol> 
    <li> List item 1 </li> 
    <li> list item 2 </li> 
</ol> 

CSS:

ol 
{ 
    display:none; 
} 
b:hover + ol{ 
    display:block; 
} 

JsFiddle


你可以阅读更多here.

+0

工作!谢啦。 – user2055171

+0

@ user2055171:欢迎您:) –

2

这是工作,我更喜欢你使用display代替visibility

<html> 
<head> 
    <title></title> 
<style> 
    b:hover + ol{ 
     display:block; 
    } 
    ol{ 
     display:none; 
    } 
</style> 
</head> 
<body> 
<b> Title of the list </b> 
<ol> 
    <li> List item 1 </li> 
    <li> list item 2 </li> 
</ol> 
</body> 
</html> 
+0

真棒谢谢! – user2055171

+0

欢迎兄弟! :) –