html - 如何使用CSS在按钮悬停时显示div

标签 html css

我的代码:

 #dropdown {
   width: 80px;
   height: 80px;
   border-radius: 80px;
   border-width: 0px;
   transition: background-color 1s;
 }
 #dropdown_word {
   font-size: 40px;
   color: orangered;
 }
 #dropdown:hover {
   background-color: cyan;
 }
<div class="heading">
  <h2>
        H2 goes here
     </h2> 
  <div class="button">
    <p>
      <button id="dropdown">
        <span id="dropdown_word"> V </span>
      </button>
    </p>
  </div>
</div>
<div class="content">
  <h4>
         H4 goes here
     </h4>
  <p>
    Text goes here
  </p>
</div>

我想当鼠标悬停在按钮上时显示类.content。在悬停之前,.content 不应对用户可见。可以使用什么 CSS 代码来获得上述输出?

最佳答案

您所要做的就是将 .content div 移动到 .button div 内并应用以下 CSS:

.content{
     display: none;
}

.button:hover .content{
     display: block;
}

这是JSFiddle .

关于html - 如何使用CSS在按钮悬停时显示div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38054812/

相关文章:

html - Ruby cgi 表错误

javascript - 在联系表单上提交时不要输入 "Leave this page"

html - CSS :Not attribute

html - 如何创建圆形旋转导航栏

html - 如何用三 Angular 形做一个透明的泡泡聊天?

css - float div 不会扩展以适应动态内容

html - 为什么 css 在悬停时向我的元素添加重复的边框?

java - 如何从网页中提取所有文本?

css - 为什么我的导航列表不向左浮动?

html - html怎么把文字放在图片的右边