Is it possible to get rid of the \"triangle\" shape in the border corners? (when using different color borders)
See this example:
http://jsfiddle.net/GLsqV/
Not everywhere with a single element. (Actually, the default triangular shape of borders is what makes great things possible: The Shapes of CSS)
However, what you are asking for is easily possible everywhere with another child element.
CSS:
.borders {
width: 520px;
height: 500px;
border-top: 10px solid red;
border-bottom: 10px solid green;
}
.borders2 {
background: #efefef;
width: 500px;
height: 500px;
border-left: 10px solid black;
border-right: 10px solid black;
}
HTML:
<div class="borders">
<div class="borders2">
</div>
</div>
With these values, the outer DIV
's border-box will still have a size of 520×520 pixels.
See also this fiddle.
One option using generated content:
.borders {
width:500px;
height:500px;
position: relative;
background:#efefef;
border-top:10px solid red;
border-bottom:10px solid green;
}
.borders::before,
.borders::after {
content: '';
position: absolute;
width: 10px;
top: 0;
bottom: 0;
background-color: #000;
}
.borders::before {
left: 0;
}
.borders::after {
right: 0;
}
JS Fiddle demo.
Or with nested HTML (if you really must):
<div class="borders">
<div class="innerBorder left"></div>
<div class="innerBorder right"></div>
</div>
.borders {
width:500px;
height:500px;
position: relative;
background:#efefef;
border-top:10px solid red;
border-bottom:10px solid green;
}
.borders .innerBorder{
content: '';
position: absolute;
width: 10px;
top: 0;
bottom: 0;
background-color: #000;
}
.borders .left {
left: 0;
}
.borders .right {
right: 0;
}
JS Fiddle demo.
And a single-nested-element solution in which the left, and right, border-color
is the background-color
of the wrapping element, and the width controlled by the margin
of the descendant:
<div class="borders">
<div class="inner"></div>
</div>
CSS:
.borders {
width:500px;
height:500px;
background-color: #000;
border-top:10px solid red;
border-bottom:10px solid green;
}
.borders .inner {
background-color: #efefef;
height: 100%;
margin: 0 10px;
}
JS Fiddle demo.
That's how borders work. How would the browser decide which ones overlap the corners otherwise?
You can achieve this effect using a nested DIV, or using a trick with :before and :after with some absolute positioning.