css - 有没有办法隐藏另一个元素下的部分?

标签 css

enter image description here

在图像中可以看到,当我制作悬停效果时,下方会显示绿色框。 当我将鼠标悬停在黄色框上时,我不想看到相交的绿色部分并且可以通过不透明度看到 有什么办法可以把相交的部分剪掉或者不显示吗?

这是我的代码:

<div class="container">
  <div class="son">
    This is a title, while has hovering, I dont should see the green square under
  </div>
</div>

.container{
  height: 507px;
  width: 500px;
  background-color: rgba(168,207,69,1);
  border-radius: 32px;
  margin-top:50px;
  z-index:1;
}
.son:hover{

  background-color: rgba(255,207,69,0.5);

}
.son{
  z-index:2;
  position:relative;
  top:-20px;
  width: 300px;
  height:50px;
  background-color: rgba(255,207,69,1);
}

https://jsfiddle.net/7zm8ascx/

最佳答案

只需在 .son:hover background-color 中使用 100% 不透明度。这将覆盖绿色矩形。 (显然,您需要更改颜色值以获得与 50% 不透明度相同的颜色。)

.container {
  background-color: rgba(168,207,69,1);
  border-radius: 32px;
  height: 500px;
  margin-top: 50px;
  width: 500px;
}
.son:hover {
  background-color: rgba(254,230,166,1);
}
.son {
  background-color: rgba(255,207,69,1);
  height: 50px;
  position: relative;
  top: -20px;
  width: 300px;
}
<div class="container">
  <div class="son">
    This is a title, while has hovering, I dont should see the green square under
  </div>
</div>

关于css - 有没有办法隐藏另一个元素下的部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55175654/

相关文章:

javascript - Firefox 中的 body 最大高度

html - Chrome 在设置了边框半径的高大对象左侧使用了错误的边框颜色

html - 输入宽度与文本区域宽度

css - 如何创建像 web what´s app 附加菜单这样的动画?

javascript - 如何在移动 View css 中相互交换 div

html - 使用纯 CSS 使单选组标签与单选按钮很好地内联显示

html - HTML5 中用于概述文档的多级编号标题

css - selenium webdriver 是否支持 css 包含?

html - 无法理解此 CSS 代码

css - 是否可以在 Bootstrap 的不同屏幕尺寸中使用 if 语句?