简体   繁体   English

如何仅使用CSS在另一个元素的悬停上显示div

[英]How can I display a div on hover of another element using only CSS

I would like to display the contents of my extra_info div when I hover over the image of the dog. 当我将鼠标悬停在狗的图像上时,我想显示我的extra_info div的内容。

I have seen syntax like : 我看过这样的语法:

.circular:hover + div.extra_info {
  display:absolute;
}

However I cannot get it to work! 但是我无法让它发挥作用!
Here is my code so far: 到目前为止,这是我的代码:

 .circular { margin-top: 50px; position: relative; z-index: 199 !important; float: left; display: block; width: 50px; height: 50px; border-radius: 50%; border: 2px solid #ffffff; } .circular:hover { border: 2px solid #16D3AE; } .extra_info { display: none; } 
 <img src=http://officialhuskylovers.com/wp-content/uploads/2015/05/Cute-dog-listening-to-music-1_1.jpg class="circular"> <div class="extra_info"> <h3>A lovely doggy woggy</h3> </div> 

View on JSFiddle 在JSFiddle上查看

You can use Adjacent sibling selector + or in this case you can also use General sibling selector ~ here is Fiddle 你可以使用Adjacent sibling selector +或者在这种情况下你也可以使用General sibling selector ~这里是Fiddle

 .circular { margin-top:50px; position: relative; z-index:199 !important; float:left; display:block; width: 50px; height: 50px; border-radius: 50%; border:2px solid #ffffff; } .circular:hover{ border:2px solid #16D3AE; } .extra_info{ display:none; } .circular:hover + .extra_info { display: block; } 
 <img src=http://officialhuskylovers.com/wp-content/uploads/2015/05/Cute-dog-listening-to-music-1_1.jpg class="circular"> <div class="extra_info"> <h3>A lovely doggy woggy</h3> </div> 

div.extra_info{
    display: none;
}

a:hover + div.extra_info{
    display: block;
}

This will work for following. 这将适用于以下。

<a>Content</a>
<div>Content display on hover</div>

div element can be build a child of the anchor. div元素可以构建锚的子元素。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 css-in-js 在 hover 另一个元素上显示 div 元素? - How to display div element on hover another element using css-in-js? 我怎么能只在div而不是div上应用动态宽度:通过CSS和JavaScript悬停 - How I can apply dynamic width only on div not on div: hover by CSS and JavaScript 如何使用css / Extjs将元素悬停在另一个元素上 - how to show an element on hover over another element using css/Extjs 如何从另一个Div(具有复杂属性)触发CSS悬停 - How can I trigger a CSS hover from another Div (with complicated attributes) 如何使用外部 JavaScript 在鼠标悬停时显示 div/元素? - How to display a div/element on mouse hover using external JavaScript? 在悬停时使用 Jquery / Javascript 显示另一个 div - On hover display another div using Jquery / Javascript 将鼠标悬停在一个Div中的元素上,该元素会更改另一个Div CSS的背景图像 - Hover on element in one Div that changes the background image of another Div CSS 当我将鼠标悬停在div的左侧/右侧时,如何显示上一个/下一个按钮(使用CSS / jQuery) - When I hover left/right side of a div how do I display previous/next button (using CSS/jQuery) 如何使用onclick函数将div标签元素与另一个div标签元素调用 - How can I call div tag element with another div tag element using onclick function 如何在JavaScript中的DOM创建元素上设置css“:hover”? - How can I set a css “:hover” on a DOM created element in JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM