简体   繁体   English

如何修复覆盖“z-index:-1”规则的背景颜色

[英]How to fix background-color covering the "z-index: -1" rule

With pure CSS code i generated some ribbons.使用纯 CSS 代码,我生成了一些丝带。

If u put a background-color or background-image to the ribbon's parent or html body, the ribbon :after and :before border-color is not shown for some reason, even with a z-index: -1 .如果您将background-colorbackground-image放在功能区的父级或 html 正文中,则功能区:after:before border-color由于某种原因不会显示,即使使用z-index: -1

The reason is that the background-color of the parent is hiding it but i can't find a solution using both, background-color and ribbon :after and :before border-colors.原因是父的background-color隐藏了它,但我找不到同时使用背景颜色和功能区的解决方案:after 和 :before border-colors。

The demonstration: http://codepen.io/anon/pen/XXOERg演示: http : //codepen.io/anon/pen/XXOERg

With z-index: -1 you position an object behind your background <div/> which has no stacking context.使用z-index: -1将一个对象放置在背景<div/>后面,该对象没有堆叠上下文。 Give it a z-index and it will work:给它一个z-index ,它会起作用:

<div class="col-md-6" style="background-color:blue;z-index:0">
    <!-- ... -->
</div>

Here is a codepen fork这是一个代码笔叉

Add the parent element:添加父元素:

position: relative;
z-index: 0;

Here is a CodePen demonstrate it这是一个CodePen演示它

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM