html - 我想要我的标题的双悬停 CSS

标签 html css

实际上,我的标题文字颜色是黑色,背景颜色是白色。但我需要,当将光标放在背景中时,它的悬停状态为蓝色,标题文本颜色变为白色。请你帮助我好吗。 enter image description here

悬停时: enter image description here

最佳答案

如果该文本在您的框内(一个 child ),那么您可以这样做。如果你想为不同的文本添加不同的颜色,应该使用下面的代码片段

.box {
  width: 100%;
  height: 300px;
  border: 1px solid red;
}

.box:hover {
  background: blue;
}

.box:hover p {
  color: white;
}
.box:hover h1 {
  color:red;
  }
<div class="box">
  <h1>Title will become red on hover</h1>
  <p>
    Some text Here will become white on hover
  </p>
</div>

如果您想更改该框内的所有文本颜色,请使用 .box:hover { background-color:blue;color:white;}

关于html - 我想要我的标题的双悬停 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45476319/

相关文章:

html - 嵌套某些 HTML 标签有限制吗?

javascript - 在 Jquery 中切换/添加/删除类未按预期工作

javascript - 滚动行为结束 : smooth scroll

javascript - 如果先前单击的元素和鼠标移动,则保持悬停类

html - 带内联 block 的交错布局,不能垂直组合框

javascript - 如何将 Internet Explorer 用户重定向到新页面?

html - 为什么具有相同百分比宽度的 div 不均匀呈现

javascript - HTML、JavaScript 和 CSS 中的自定义弹出框

html - 将边距从像素转换为百分比 - 打破左浮动元素

html - 文本对齐 :center is not doing well with width and display: inline-block