Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent border with background color

Tags:

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

like image 230
Kaya Toast Avatar asked Feb 19 '15 10:02

Kaya Toast


People also ask

How do you make a transparent border color?

Step 1: Create a div tag. Step 2: Specify the border-style property to be double to set two borders around the box. Step 3: Set the background-clip property to padding-box which clips the background color to the padding of the element.

How do you make a transparent border?

Click "Edit" and select "Fill" to get options to fill the border with a color or pattern. You'll also get the option to set the opacity, which will determine how transparent your border is. Set the opacity to 100 percent for a fully transparent border, or 50 percent for a semi-transparent border.

How do you make a border transparent in CSS?

The easiest solution to this is to use rgba as the color: border-color: rgba(0,0,0,0); That is fully transparent border color.


1 Answers

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.

like image 149
web-tiki Avatar answered Oct 13 '22 00:10

web-tiki