简体   繁体   English

具有背景色的透明边框

[英]Transparent border with background color

This is strange. 这很奇怪。

This works: 这有效:

border-right: 1px solid rgba(0,0,0,0.12);
/* renders a gray border */

But when I use it together with background color, then border is now a solid black line. 但是,当我将其与背景色一起使用时,边框现在是一条实心黑线。

background-color: #333;
border-right: 1px solid rgba(0,0,0,0.12);
/* renders a black border */

Am I missing something ? 我想念什么吗?

http://codepen.io/anon/pen/myxpXN http://codepen.io/anon/pen/myxpXN

The behaviour you are experiencing is that the background of the element appears through the transparent border. 您遇到的行为是元素的背景通过透明边框显示。 If you want to prevent this and clip the background inside the border, you can use: 如果要防止这种情况并在边框内修剪背景,可以使用:

background-clip: padding-box;

 html, body { height: 100%; margin: 0; padding: 0; background:green; } #nav { position:relative; height: 100%; width: 240px; background-clip: padding-box; /** <-- this **/ background-color: pink; border-right: 10px solid rgba(0,0,0,0.12); } header { height: 4em; background-color: #ffffff; } 
 <div id="nav"> <header></header> <nav></nav> </div> 

More info about background-clip on MDN. 有关MDN上的background-clip的更多信息。

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

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