CSS - 翻转一个元素,并使另一个元素可见

时间:2022-11-03 00:20:44

In CSS, is it possible that when I rollover one element, I make another element visible? I have an icon, and when someone mouses over it, I want it to make visible a text element that describes what the icon does.

在CSS中,当我翻转一个元素时,是否可能使另一个元素可见?我有一个图标,当有人将鼠标悬停在它上面时,我希望它能够显示一个描述图标功能的文本元素。

5 个解决方案

#1


17  

Here's a CSS only tooltip I use all the time :) Works great, even in IE.

这是我一直使用的CSS工具提示:)工作得很好,即使在IE中也是如此。

a:hover {
background:#ffffff; 
text-decoration:none;
} 
/*BG color is a must for IE6*/

a.tooltip span {
display:none; 
padding:2px 3px; 
margin-left:8px; 
width:130px;
}

a.tooltip:hover span{
display:inline; 
position:absolute; 
background:#ffffff; 
border:1px solid #cccccc; 
color:#6c6c6c;
}

Easy 

<a class="tooltip" href="#">
Tooltip
<span>T his is the crazy little Easy Tooltip Text.
</span>
</a>

Hope it helps.

希望能帮助到你。

#2


6  

You can make child-elements visible by hovering on the parent (as Hunter suggests), or siblings:

您可以通过将鼠标元素悬停在父级(如Hunter建议)或兄弟姐妹中来显示子元素:

span:hover + span {display: block; }

There are maybe some slight cross-browser compatibility issues, but with a valid doctype I think IE7+ is okay with sibling selectors (though I've not tried to test that theory).

可能有一些轻微的跨浏览器兼容性问题,但有了一个有效的doctype,我认为IE7 +对于兄弟选择器是可以的(尽管我没有试过测试该理论)。

#3


3  

sure it is!

当然是啦!

.me:hover span { display: block; }

If you want to show an element that isn't a child of the element hovered you might need to use javascript

如果要显示一个不是元素悬停元素的元素,则可能需要使用javascript

#4


1  

Here's a little slapped-together example that won't work on IE...

这里有一个简单的例子,不适用于IE ...

<html>
<head>
<style>
    div.tooltip
    {
        margin-top: 16px;
        margin-left: -1px;
        position: absolute;
        border: 1px solid black;
        background-color: blue;
        color: yellow;
        display: none;
    }
    div.icon
    {
        width: 16px;
        height: 16px;
        border: 1px solid blue;
        background-color: cyan;
    }
    div.icon:hover .tooltip
    {
        display: block;
    }
</style>
</head>
<body>
    <div class="icon">
        <div class="tooltip">This is what the icon does.</div>
    </div>
</body>
</html>

But you really should just use jQuery.

但你真的应该只使用jQuery。

#5


0  

Agree with the JavaScript recommendation. Specifically jQuery is easy and most appropriate for page behavior logic. I think CSS should only be look/feel/style...Javascript should be were all your event and behavior logic is.

同意JavaScript推荐。具体来说,jQuery很简单,最适合页面行为逻辑。我认为CSS应该只是外观/感觉/风格...... Javascript应该是你所有的事件和行为逻辑。

#1


17  

Here's a CSS only tooltip I use all the time :) Works great, even in IE.

这是我一直使用的CSS工具提示:)工作得很好,即使在IE中也是如此。

a:hover {
background:#ffffff; 
text-decoration:none;
} 
/*BG color is a must for IE6*/

a.tooltip span {
display:none; 
padding:2px 3px; 
margin-left:8px; 
width:130px;
}

a.tooltip:hover span{
display:inline; 
position:absolute; 
background:#ffffff; 
border:1px solid #cccccc; 
color:#6c6c6c;
}

Easy 

<a class="tooltip" href="#">
Tooltip
<span>T his is the crazy little Easy Tooltip Text.
</span>
</a>

Hope it helps.

希望能帮助到你。

#2


6  

You can make child-elements visible by hovering on the parent (as Hunter suggests), or siblings:

您可以通过将鼠标元素悬停在父级(如Hunter建议)或兄弟姐妹中来显示子元素:

span:hover + span {display: block; }

There are maybe some slight cross-browser compatibility issues, but with a valid doctype I think IE7+ is okay with sibling selectors (though I've not tried to test that theory).

可能有一些轻微的跨浏览器兼容性问题,但有了一个有效的doctype,我认为IE7 +对于兄弟选择器是可以的(尽管我没有试过测试该理论)。

#3


3  

sure it is!

当然是啦!

.me:hover span { display: block; }

If you want to show an element that isn't a child of the element hovered you might need to use javascript

如果要显示一个不是元素悬停元素的元素,则可能需要使用javascript

#4


1  

Here's a little slapped-together example that won't work on IE...

这里有一个简单的例子,不适用于IE ...

<html>
<head>
<style>
    div.tooltip
    {
        margin-top: 16px;
        margin-left: -1px;
        position: absolute;
        border: 1px solid black;
        background-color: blue;
        color: yellow;
        display: none;
    }
    div.icon
    {
        width: 16px;
        height: 16px;
        border: 1px solid blue;
        background-color: cyan;
    }
    div.icon:hover .tooltip
    {
        display: block;
    }
</style>
</head>
<body>
    <div class="icon">
        <div class="tooltip">This is what the icon does.</div>
    </div>
</body>
</html>

But you really should just use jQuery.

但你真的应该只使用jQuery。

#5


0  

Agree with the JavaScript recommendation. Specifically jQuery is easy and most appropriate for page behavior logic. I think CSS should only be look/feel/style...Javascript should be were all your event and behavior logic is.

同意JavaScript推荐。具体来说,jQuery很简单,最适合页面行为逻辑。我认为CSS应该只是外观/感觉/风格...... Javascript应该是你所有的事件和行为逻辑。