Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a border that fully covers the adjacent corners in CSS?

Tags:

I have a div with a 1px border and I'm trying to create a 3px border in another color to that div. I'm using this code:

box {   border: 1px solid #ddd;   border-top: 3px solid #3F9BD0; } 

but at the corners the border is not good, see image:
bad border

How can I make this border look good, like this:
desired border with right-angled corners

fiddle: https://jsfiddle.net/15tory3z/

like image 306
AlbaStar Avatar asked Sep 02 '15 10:09

AlbaStar


People also ask

How do you make a side all border in CSS?

If the border-style property has three values: border-style: dotted solid double; top border is dotted. right and left borders are solid.

How do you cut a border corner in CSS?

Here is another approach using CSS transform: skew(45deg) to produce the cut corner effect. The shape itself involves three elements (1 real and 2 pseudo-elements) as follows: The main container div element has overflow: hidden and produces the left border.


2 Answers

Instead of border-top, try using the :after pseudo-element to recreate the effect you want.

.box {    width: 200px;    height: 100px;    border: 1px solid #ddd;    position: relative;  }  .box:after {    position: absolute;    content: "";    width: 100%;    height: 5px;    top: -5px;    background: dodgerblue;    padding: 1px;    left: -1px;  }
<div class="box"></div>

Choice 2:

Use linear-gradient().

.box {    width: 200px;    height: 100px;    border: 1px solid #ddd;    background: -webkit-linear-gradient(top, dodgerblue 5%, #fff 5%);    background: -moz-linear-gradient(top, dodgerblue 5%, #fff 5%);    background: -o-linear-gradient(top, dodgerblue 5%, #fff 5%);    background: -ms-linear-gradient(top, dodgerblue 5%, #fff 5%);    background: linear-gradient(top, dodgerblue 5%, #fff 5%);  }
<div class="box"></div>
like image 113
Akshay Avatar answered Oct 06 '22 00:10

Akshay


You could draw these with inset shadows and padding :

div {    padding:12px 5px 5px;    width: 40%;    height: 200px;    box-shadow: inset 0 10px #3F9BD0, inset 4px 0 gray, inset -4px 0 gray, inset 0 -4px  gray  }
<div></div>

or just an outset top shadow

div {       width: 40%;    height: 200px;    border:2px solid gray;    border-top:none;    box-shadow:  0 -10px #3F9BD0;    margin-top:12px;  }
<div></div>

else, background gradient could be used and even animated 2 examples : http://codepen.io/gc-nomade/pen/IGliC or http://codepen.io/gc-nomade/pen/pKwby

like image 28
G-Cyrillus Avatar answered Oct 05 '22 23:10

G-Cyrillus