Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Div border in this form: blank gaps in the corners

Tags:

html

css

border

How to accomplish this div border using css:
enter image description here

I tried using dashed border but leads to this:
http://jsfiddle.net/23qGr/

div {width: 20px; 
height: 20px; border: 6px #6a817d dashed; 
-webkit-border-radius: 5px; 
-moz-border-radius: 5px; 
border-radius: 5px;
}
like image 758
elsadek Avatar asked Jun 01 '14 14:06

elsadek


People also ask

How do you put a border inside a div?

Answer: Use the CSS box-shadow property If you want to place or draw the borders inside of a rectangular box there is a very simple solution — just use the CSS outline property instead of border and move it inside of the element's box using the CSS3 outline-offset property with a negative value.

Why border-radius is not working on div?

If there are contents within the div that has the curved corners, you have to set overflow: hidden because otherwise the child div's overflow can give the impression that the border-radius isn't working. This answer worked for me.

Is CSS border inside or outside?

Width and height values apply to the element's content only. The padding and border are added to the outside of the box. padding-box : Width and height values apply to the element's content and its padding. The border is added to the outside of the box.


1 Answers

You could use pseudo element and transparent/black borders : DEMO

div {
    width: 20px;
    height: 20px;
    padding:6px;
    position:relative;
}
div:before , div:after {
    content:'';
    border:6px solid transparent;
    position:absolute;
}
div:before {
    left:2px;
    right:2px;
    top:0;
    bottom:0;
    border-top-color:black;
    border-bottom-color:black;
}
div:after {
    top:2px;
    bottom:2px;
    left:0;
    right:0;
    border-right-color:black;
    border-left-color:black;
}

If you increse border-width, it looks better : demo

like image 61
G-Cyrillus Avatar answered Nov 15 '22 05:11

G-Cyrillus