html - 如何通过半透明的 div 显示框阴影?

标签 html opacity css

我有一个带有此 css 的 div 元素:

  height: 50px;
  width: 50px;
  background-color: rgba(0, 0, 0, 0.5);
  box-shadow: 20px 20px 5px red;

screenshot of the result

尽管它是半透明的,但我看不到 div 下的红色阴影。有什么办法可以显示吗?

编辑:因为这可能是渲染问题,我在 Google Chrome、Firefox 和 IE 中进行了测试,结果相同。

最佳答案

据我所知,你不能用盒子阴影来实现这一点。

可以通过伪元素获取:

.test {
    height: 50px;
    width: 50px;
    background-color: rgba(0, 0, 0, 0.5);
    position: relative;
}

.test:after {
    content: "";
    width: 100%;
    height: 100%;
    left: 20px;
    top: 20px;
    background-color: red;
    box-shadow: 0px 0px 5px red;
    position: absolute;
    z-index: -1;
}

我在伪元素中设置了阴影只是为了模糊。其他阴影属性转到伪元素的左侧和顶部属性。

fiddle

关于html - 如何通过半透明的 div 显示框阴影?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22511800/

相关文章:

html - 获取位于每个图像顶部的链接

html - 如何使用 CSS 降低元素背景的不透明度?

jquery - 悬停时动画不透明度 (jQuery)

html - 如何为自动高度元素水平而不是垂直排列 CSS 列?

jquery - 如何仅使用 jquery 为中间 3 个 div 着色

javascript - HTML5 Canvas 游戏生成间隔

jquery - css- css 样式与另一个 css 文件冲突

javascript - Bootstrap 模态背景滚动问题

HTML 到 Excel : How can tell Excel to treat columns as numbers?

CSS 不透明背景颜色和文本不起作用