I’m trying to realise a couples of element with this design :
I also want to have a border radius like this :
What I managed to do :
For the first div, I didn’t managed to do inner box shadow for the ::before arrow and box shadow for the ::after arrow
For the last div, I managed to do it but when I try to change the size of the arrow to make it larger, the box-shadows is not working anymore...
body {
background-color: white;
}
.test{
margin-top: -30px!important;
}
.test2{
z-index:13;
}
.test3{
z-index:12;
}
.test4{
z-index:11;
}
.test5{
z-index:10;
}
.triangle {
position: relative;
margin: 3em;
padding: 1em;
box-sizing: border-box;
background: white;
box-shadow: 0px 3px 10px 0 black;
}
.triangle::before{
content: "";
position: absolute;
width: 0;
height: 0;
margin-left: -0.5em;
top: 0;
left: 40%;
width: 0;
height: 0;
border-style: solid;
border-width: 20px 50px 0 50px;
border-color: lightgrey transparent transparent transparent;
//box-shadow: 0px 3px 10px 0 black;
}
.triangle::after{
content: "";
position: absolute;
width: 0;
height: 0;
margin-left: -0.5em;
bottom: -20px;
left: 40%;
width: 0;
height: 0;
border-style: solid;
border-width: 20px 50px 0 50px;
border-color: lightgrey transparent transparent transparent;
//box-shadow: 0px 3px 10px 0 black;
}
.toto::after{
content: "";
position: absolute;
width: 0;
height: 0;
margin-left: -0.5em;
bottom: -2em;
left: 50%;
box-sizing: border-box;
border: 1em solid black;
border-color: transparent transparent lightgrey lightgrey;
transform-origin: 0 0;
transform: rotate(-45deg);
box-shadow: -3px 3px 3px 0 rgba(0, 0, 0, 0.4);
}
<div class="triangle test2">Inner box shadow for before content not working</div>
<div class="triangle test test3">box shadow for after content not working</div>
<div class="triangle test test4">Content 3</div>
<div class="triangle test test5">Content 4</div>
<div class="triangle toto">Managed to do it but the arrow is not editable(I want to make it longer)</div>
Anyone already had this issue or know how to solve this problem?
This is suitable for clip-path
.box {
margin: 50px;
height: 100px;
position:relative;
z-index:0;
filter: drop-shadow(0 0 5px #000);
}
.box::before {
content:"";
position:absolute;
z-index:-1;
top:0;
left:0;
right:0;
bottom:0;
background: #f2f2f2;
clip-path: polygon(
0 0,
calc(50% - 20px) 0, 50% 20px, calc(50% + 20px) 0, /* top arrow */
100% 0,
100% calc(100% - 20px),
calc(50% - 20px) calc(100% - 20px), 50% 100%, calc(50% + 20px) calc(100% - 20px), /* bottom arrow */
0 calc(100% - 20px));
}
<div class="box"></div>
With CSS variables you can easily handle it:
.box {
--w:40px; /* width of the arrow */
--h:20px; /* height of the arrow */
margin: 50px;
height: 100px;
padding:var(--h) 0;
position:relative;
z-index:0;
filter: drop-shadow(0 0 5px #000);
}
.box::before {
content:"";
position:absolute;
z-index:-1;
top:0;
left:0;
right:0;
bottom:0;
background: #f2f2f2;
clip-path: polygon(
0 0,
calc(50% - var(--w)/2) 0, 50% var(--h), calc(50% + var(--w)/2) 0, /* top arrow */
100% 0,
100% calc(100% - var(--h)),
calc(50% - var(--w)/2) calc(100% - var(--h)), 50% 100%, calc(50% + var(--w)/2) calc(100% - var(--h)), /* bottom arrow */
0 calc(100% - var(--h)));
}
<div class="box"></div>
<div class="box" style="--w:60px;"></div>
<div class="box" style="--w:200px;--h:40px"></div>
To add border radius you can edit like below:
.box {
--w: 40px; /* width of the arrow */
--h: 20px; /* height of the arrow */
--r: 30px; /* radius */
margin: 50px;
height: 100px;
padding: var(--h) 0;
position: relative;
z-index: 0;
filter: drop-shadow(0 0 5px #000);
}
.box::before,
.box::after {
content: "";
position: absolute;
z-index: -1;
left: 0;
right: 0;
background: #f2f2f2;
}
.box::before {
top: 0;
bottom: var(--h);
border-radius: var(--r);
clip-path: polygon( 0 0, calc(50% - var(--w)/2) 0, 50% var(--h), calc(50% + var(--w)/2) 0, 100% 0, 100% 100%, 0 100%);
}
.box::after {
bottom: 0;
height: var(--h);
clip-path: polygon( 0 0, 100% 0, calc(50% - var(--w)/2) 0, 50% 100%, calc(50% + var(--w)/2) 0);
}
<div class="box"></div>
<div class="box" style="--w:60px;--r:20px"></div>
<div class="box" style="--w:200px;--h:40px;--r:60px"></div>
You may use filter / drop-shadow
https://developer.mozilla.org/en-US/docs/Web/CSS/filter-function/drop-shadow
The drop-shadow() CSS function applies a drop shadow effect to the input image. Its result is a <filter-function>.
possible use :
body {
background-color: white;
}
.test {
margin-top: -30px!important;
}
.test2 {
z-index: 13;
}
.test3 {
z-index: 12;
}
.test4 {
z-index: 11;
}
.test5 {
z-index: 10;
}
.triangle {
position: relative;
margin: 3em;
padding: 1em;
box-sizing: border-box;
background: white;
filter: drop-shadow(0px 3px 10px black);
}
.triangle::after {
content: "";
position: absolute;
width: 0;
height: 0;
margin-left: -0.5em;
bottom: -20px;
left: 40%;
width: 0;
height: 0;
border-style: solid;
border-width: 20px 50px 0 50px;
border-color: white transparent transparent transparent;
}
.toto::after {
content: "";
position: absolute;
width: 0;
height: 0;
margin-left: -0.5em;
bottom: -2em;
left: 50%;
box-sizing: border-box;
border: 1em solid black;
border-color: transparent transparent white white;
transform-origin: 0 0;
transform: rotate(-45deg);
}
<div class="triangle test2">Inner box shadow for before content not working</div>
<div class="triangle test test3">box shadow for after content not working</div>
<div class="triangle test test4">Content 3</div>
<div class="triangle test test5">Content 4</div>
<div class="triangle toto">Managed to do it but the arrow is not editable(I want to make it longer)</div>
Related
I'm trying to achieve the shape as shown in this image:
To have 2 rectangle divs with cut corners , and 1 div positioned behind another div.
But the corners seems incorrect and I can't find the way to show the borders of the shapes.
.wrapper {
display: flex;
justify-content: center;
}
.connect {
width: 254px;
height: 50px;
background: red;
background: #FF2D5069;
border-top: 2px solid #FF2175;
position: absolute;
bottom: 0;
z-index: 5;
}
.connect::before {
content: '';
position: absolute;
bottom: 0;
right: -2px;
border-top: 52px solid white;
border-left: 42px solid transparent;
}
.connect::after {
content: '';
position: absolute;
bottom: 0;
left: -2px;
border-top: 52px solid white;
border-right: 42px solid transparent;
}
.connect-behind {
width: 300px;
height: 44px;
background: red;
background: #FF2D5069;
border-top: 2px solid #FF2175;
position: absolute;
bottom: 0;
}
.connect-behind::before {
content: '';
position: absolute;
bottom: 0;
right: -2px;
border-top: 46px solid white;
border-left: 26px solid transparent;
}
.connect-behind::after {
content: '';
position: absolute;
bottom: 0;
left: -2px;
border-top: 46px solid white;
border-right: 26px solid transparent;
}
<div class="wrapper">
<div class="connect"></div>
<div class="connect-behind"></div>
</div>
I took reference from other threads to use behind and after for the solution but it doesn't seem working correct for my problem. Please help, thanks.
You could use perspective and transform:
possible example (for infos : with grid instead absolute) :
.wrapper {
display: grid;
justify-content: center;
align-items: end;
height: 300px;
perspective: 50px;
}
.connect,
.connect-behind {
transform: rotatex(50deg);
background: red;
margin: 0 auto;
background: #FF2D5069;
border-top: 2px solid #FF2175;
grid-row: 1;
grid-column: 1;
transform-origin: bottom center;
}
.connect-behind {
width: 300px;
height: 44px;
}
.connect {
width: 254px;
height: 50px;
;
}
<div class="wrapper">
<div class="connect"></div>
<div class="connect-behind"></div>
</div>
to draw a border around the shape, drop-shadow could be usefull
.wrapper {
display: grid;
justify-content: center;
align-items: end;
height: 300px;
perspective: 50px;
filter:
drop-shadow( 1px 0px 0 )
drop-shadow(-1px 0px 0 )
drop-shadow( 0px 1px 0 )
drop-shadow( 0px -1px 0 );
}
.connect,
.connect-behind {
transform: rotatex(50deg);
background: red;
margin: 0 auto;
background:white;
grid-row: 1;
grid-column: 1;
transform-origin: bottom center;
background:#ffa500;
}
.connect-behind {
width: 254px;
height: 50px;
border-left:solid 2px;
border-right:solid 2px;
}
.connect {
background:#ed1c24;
width: 300px;
height: 44px;
;
}
<div class="wrapper">
<div class="connect"></div>
<div class="connect-behind"></div>
</div>
You can use clip-path for things like this. Works well in a ( I think ) most browsers. Some, like ie11 and older browsers won't render it correctly, though, so you may need a fallback for those cases.
body {
overflow: hidden;
}
.wrapper {
display: flex;
justify-content: center;
}
.connect {
width: 254px;
height: 80px;
background: red;
background: #FF2D5069;
border-top: 2px solid black;
position: absolute;
bottom: 0;
z-index: 5;
clip-path: polygon(20% 0%, 80% 0%, 100% 100%, 0% 100%);
}
.connect-border-left {
height: 80px;
width: 2px;
background: black;
left: calc(50% - 131px);
position: absolute;
bottom: -12px;
transform: rotate(34deg) translateX(-50%);
display: inline-block;
}
.connect-border-right {
height: 80px;
width: 2px;
background: black;
right: calc(50% - 131px);
position: absolute;
bottom: -12px;
transform: rotate(-34deg) translateX(-50%);
display: inline-block;
}
.connect-behind {
width: 300px;
height: 60px;
background: red;
background: #FF2D5069;
border-top: 2px solid black;
position: absolute;
bottom: 0;
clip-path: polygon(14% 0%, 86% 0%, 100% 100%, 0% 100%);
}
.connect-behind-border-right {
height: 100px;
width: 2px;
background: black;
right: calc(50% - 103px);
position: absolute;
bottom: -11px;
transform: rotate(-32deg) translateX(-50%);
display: inline-block;
}
.connect-behind-border-left {
height: 100px;
width: 2px;
background: black;
left: calc(50% - 103px);
position: absolute;
bottom: -11px;
transform: rotate(32deg) translateX(-50%);
display: inline-block;
}
<div class="wrapper">
<div class="connect"></div>
<div class="connect-border-left"></div>
<div class="connect-border-right"></div>
<div class="connect-behind"></div>
<div class="connect-behind-border-left"></div>
<div class="connect-behind-border-right"></div>
</div>
an idea with skew transformation, clip-path and multiple background:
.box {
--b:3px; /* border width */
--t:20px; /* top part width */
--s:30px; /* side part width */
margin:10px;
display:inline-block;
width:250px;
height:150px;
position:relative;
}
.box::before,
.box::after {
content:"";
position:absolute;
top:0;
bottom:0;
left:0;
width:50%;
border-style:solid;
border-width:var(--b) 0 0 var(--b);
background:
linear-gradient(black 0 0) 0 var(--t)/100% var(--b),
linear-gradient(black 0 0) var(--s) 0/var(--b) 100%,
linear-gradient(red 0 0) left/var(--s) 100%,
orange;
background-repeat:no-repeat;
transform-origin:bottom right;
transform:skew(-20deg);
clip-path:polygon(0 calc(var(--t) + var(--b)), calc(var(--s) + var(--b)) calc(var(--t) + var(--b)),calc(var(--s) + var(--b)) 0,60% 0,100% 100%,0 100%);
}
.box::after {
transform:scale(-1,1) skew(-20deg);
}
<div class="box"></div>
<div class="box" style="--b:2px;--t:30px;--s:15px;"></div>
So I've managed to create a CSS Triangle with 3 different coloured borders. It can be seen here: https://codepen.io/nuul/pen/oNbeZey
CSS code:
$bg: #0000e5
$color: ((#00007c, #0000e5), (#0000b0, #0000e5), (#0000ff, #0000e5))
#mixin linear-gradient($direction, $gradients...)
background-image: linear-gradient($direction, $gradients...)
#function colorL($some-color, $num)
#return nth($some-color, $num)
#for $i from 1 through length($color)
.sq-#{$i}
#include linear-gradient(colorL(nth($color, $i), 2) 60%, colorL(nth($color, $i), 1) 75%)
$height: 9px
$width: $height * 3.47
body
background: #3D4849
.blueCore
position: absolute
left: 5px
top: 15px
.sq-wrapper
width: $width
height: $height
font-size: 0
display: inline-block
clip-path: polygon(50% 0%, 0 100%, 100% 100%)
position: absolute
left: 0
top: $height
transform-origin: 50% 0
.sq-1-wrapper
transform: rotate(0deg)
.sq-2-wrapper
transform: rotate(240deg)
.sq-3-wrapper
transform: rotate(-240deg)
.sq
width: 100%
height: 100%
.blueBlock
background-color: #0000e5
border: 3px solid
border-top-color: #0000ff
border-right-color: #00007c
border-bottom-color: #00007c
border-left-color: #0000ff
width: 42px
height: 42px
position: relative
z-index: 10
Though I am happy with the result, I am still wondering if the CSS code for this can be simplified (since there is a lot of CSS code needed for just a triangle). Perhaps with a :before :after? The looks should stay the same
Any thoughts?
ps: You can ignore the square around it, I just want to put it in a div for future usage
Thanks!
In terms of your question, I wouldn't recommend using CSS for this and maybe in this situation, an image or even font-awesome would be more efficient. However, you could possibly tweak something like below. It uses two elements to create this shape.
.outer {
position: relative;
height: 200px;
width: 200px;
background: dimgray;
}
.outer:before {
/*Bottom Border Here*/
content: "";
position: absolute;
height: 10%;
width: 90%;
left: 5%;
top: 88%;
z-index: 10;
background: darkblue;
transform: perspective(100px) rotateX(60deg);
}
.outer:after {
/*Triangle Background*/
content: "";
position: absolute;
width: 0;
left: 10px;
bottom: 10px;
border-top: 0;
border-left: 90px solid transparent;
border-right: 90px solid transparent;
border-bottom: 150px solid blue;
}
.inner {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
}
.inner:before {
content: "";
position: absolute;
height: 10%;
width: 90%;
left: -17%;
top: 50%;
background: lightblue;
/*Left border colour here*/
transform: rotate(121deg) perspective(100px) rotateX(60deg);
}
.inner:after {
content: "";
position: absolute;
height: 10%;
width: 90%;
right: -18%;
top: 50%;
background: rgb(0, 0, 220);
/*right border colour here*/
transform: rotate(-120deg) perspective(100px) rotateX(60deg);
}
/*demo only*/
.outer:hover:before { background: darkred;}
.outer:hover:after { border-bottom-color: red;}
.outer:hover .inner:before { background: tomato;}
.outer:hover .inner:after { background: rgb(220, 0, 0);}
<div class="outer">
<div class="inner"></div>
</div>
one element and responsive solution:
.box {
width: 200px;
display: inline-flex;
background:
conic-gradient(at 50% 20px, red 150deg, #0000 0 210deg, green 0)
blue;
clip-path: polygon(50% 0, 100% 100%, 0 100%);
}
.box::before {
content: "";
padding-top: calc(86.6% - 10px);
width: 100%;
box-sizing: border-box;
border:solid transparent;
border-bottom-color: gold;
border-width: 0 18px 10px 18px;
}
<div class="box"></div>
<div class="box" style="width:150px;"></div>
<div class="box" style="width:50px;"></div>
I want to make the following design:
I tried with :after and :before but it does not work. Here’s my current code:
.design {
background: #ea053a;
display: inline-block;
height: 155px;
margin-left: 33px;
margin-right: 40px;
position: relative;
width: 228px;
}
.design:before {
border-top: 43px solid #ea053a;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
margin-right: 40px;
content: "";
height: 0;
left: 0;
position: absolute;
top: 55px;
margin-top: 100px;
width: 128px;
}
<div class="design"></div>
How could I leave it the same as the original design and with the following two properties?:
box-shadow: 0 1px 10px 0 rgba(0, 0, 0, 0.2);
background-image: linear-gradient(to bottom, #ea053a, #d0021b);
Here is an idea with skew transformation and drop-shadow filter. You simply need some extra element to correctly have the gradient. The trick is to invert the skew to keep the gradient direction correct (not needed if we deal with solid color)
.box {
width: 150px;
height: 150px;
position: relative;
z-index:0;
overflow: hidden;
filter: drop-shadow(0 1px 10px rgba(0, 0, 0, 0.8));
}
.box span {
position: absolute;
z-index:-1;
top: 0;
width: 50%;
height: 100%;
overflow: hidden;
}
.box span:first-of-type {
left: 0;
transform: skewY(35deg);
transform-origin: top right;
}
.box span:last-of-type {
right: 0;
transform: skewY(-35deg);
transform-origin: top left;
}
.box span::before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(to bottom, blue , red );
transform-origin: inherit;
}
.box span:first-of-type::before {
transform: skewY(-35deg);
}
.box span:last-of-type::before {
transform: skewY(35deg);
}
p {
margin:0;
color:#fff;
font-size:45px;
line-height:100px;
text-align:center;
}
<div class="box">
<span></span><span></span>
<p>29</p>
</div>
Here is how we can do with a left or right gradient. In this case we don't need extra elements because the skew will not affect the direction:
.box {
width: 150px;
height: 150px;
position: relative;
z-index:0;
overflow: hidden;
filter: drop-shadow(0 1px 10px rgba(0, 0, 0, 0.8));
}
.box:before,
.box:after{
content:"";
position: absolute;
z-index:-1;
top: 0;
width: 50%;
height: 100%;
overflow: hidden;
background:linear-gradient(to right,blue,red);
background-size:200% 100%;
}
.box:before{
left: 0;
transform: skewY(35deg);
transform-origin: top right;
}
.box:after{
right: 0;
transform: skewY(-35deg);
transform-origin: top left;
background-position:right;
}
p {
margin:0;
color:#fff;
font-size:45px;
line-height:100px;
text-align:center;
}
<div class="box">
<p>29</p>
</div>
And here is with an arbitrary gradient:
.box {
--g:linear-gradient(45deg,blue,red 60%,yellow); /* gradient coloration*/
width: 150px;
height: 150px;
margin:15px;
display:inline-block;
position: relative;
z-index:0;
overflow: hidden;
filter: drop-shadow(0 1px 10px rgba(0, 0, 0, 0.8));
}
.box span {
position: absolute;
z-index:-1;
top: 0;
width: 50%;
height: 100%;
overflow: hidden;
}
.box span:first-of-type {
left: 0;
transform: skewY(35deg);
transform-origin: top right;
}
.box span:last-of-type {
right: 0;
transform: skewY(-35deg);
transform-origin: top left;
}
.box span::before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: var(--g);
background-size:200% 100%;
transform-origin: inherit;
}
.box span:first-of-type::before {
transform: skewY(-35deg);
}
.box span:last-of-type::before {
transform: skewY(35deg);
background-position:right;
}
p {
margin:0;
color:#fff;
font-size:45px;
line-height:100px;
text-align:center;
}
<div class="box">
<span></span><span></span>
<p>29</p>
</div>
<div class="box" style="--g:linear-gradient(-62deg,blue,red 60%,yellow)">
<span></span><span></span>
<p>29</p>
</div>
Since each element is taking 50% of the width we make the background to be 200% to have its size as the main container then we adjust the position to create the illusion of one background. It's like each element will show half of the main background.
An optimized version using mask
.box {
width: 150px;
height: 150px;
filter: drop-shadow(0 1px 10px rgba(0, 0, 0, 0.8));
}
.box > div {
height: 100%;
background: linear-gradient(35deg, blue, red);
-webkit-mask:
linear-gradient(#fff, #fff) top/100% 70%,
linear-gradient(to bottom right, #fff 49.5%, transparent 50%) bottom right/50% 30%,
linear-gradient(to bottom left, #fff 49.5%, transparent 50%) bottom left /50% 30%;
mask:
linear-gradient(#fff, #fff) top/100% 70%,
linear-gradient(to bottom right, #fff 49.5%, transparent 50%) bottom right/50% 30%,
linear-gradient(to bottom left, #fff 49.5%, transparent 50%) bottom left /50% 30%;
-webkit-mask-repeat: no-repeat;
mask-repeat: no-repeat;
}
p {
margin: 0;
color: #fff;
font-size: 45px;
line-height: 100px;
text-align: center;
}
<div class="box">
<div>
<p>29</p>
</div>
</div>
Or clip-path
.box {
width: 150px;
height: 150px;
filter: drop-shadow(0 1px 10px rgba(0, 0, 0, 0.8));
}
.box > div {
height: 100%;
background: linear-gradient(35deg, blue, red);
clip-path:polygon(0 0,100% 0,100% 70%,50% 100%,0 70%);
}
p {
margin: 0;
color: #fff;
font-size: 45px;
line-height: 100px;
text-align: center;
}
<div class="box">
<div>
<p>29</p>
</div>
</div>
You can use clip-path as I did. Here is my solution.
.design {
background: #ea053a;
-webkit-clip-path: polygon(50% 0%, 100% 0, 100% 75%, 50% 100%, 0% 75%, 0 0);
clip-path: polygon(50% 0%, 100% 0, 100% 75%, 50% 100%, 0% 75%, 0 0);
height: 155px;
width: 155px;
}
.month {
text-align:center;
padding: 1rem 0 .25rem 0;
color:#fff;
font-weight:bold;
font-size: 18px;
}
.day {
text-align: center;
font-size: 60px;
font-weight:bold;
color: #fff;
}
<div class="design">
<div class="month">Diciembre</div>
<div class="day">29</div>
</div>
If you change your CSS to the following minor changes, then you can achieve the result that you have expected:
.design {
background: #ea053a;
display: inline-block;
height: 100px;
margin-left: 33px;
margin-right: 40px;
position: relative;
width: 180px;
}
.design:before {
border-top: 43px solid #ea053a;
border-left: 90px solid transparent;
border-right: 90px solid transparent;
margin-right: 40px;
content: "";
height: 0;
left: 0;
position: absolute;
top: 0px;
margin-top: 100px;
width: 0;
}
Here is the working of the above CSS:
.design {
background: #ea053a;
display: inline-block;
height: 100px;
margin-left: 33px;
margin-right: 40px;
position: relative;
width: 180px;
}
.design:before {
border-top: 43px solid #ea053a;
border-left: 90px solid transparent;
border-right: 90px solid transparent;
margin-right: 40px;
content: "";
height: 0;
left: 0;
position: absolute;
top: 0px;
margin-top: 100px;
width: 0;
}
<div class="design">
</div>
Hope this was helpful.
My Fiddle
Change to (only changed lines listed, keep everything else as-is):
.design:before {
...
border-left: 114px solid transparent;
border-right: 114px solid transparent;
...
width: 0;
}
Here is my solution to add shadow and gradient to the shape
.design {
background: #ea053a;
display: inline-block;
height: 155px;
margin-left: 33px;
margin-right: 40px;
position: relative;
width: 228px;
filter: drop-shadow(0 1px 10px rgba(0, 0, 0, 0.8));
}
.triangle {
position: absolute;
height: 100px;
top: 155px;
width: 228px;
-webkit-clip-path: polygon(49% 44%, 0% 100%, 100% 100%);
clip-path: polygon(49% 44%, 0% 100%, 100% 100%);
background-color: #ea053a;
transform: rotate(180deg);
}
<div class="design">
<div class="triangle">
</div>
</div>
I wanted to achieve triple border like below image.
I have tried below solution but, the corners are still looking different. it is not overlapping.
.dtborder {
position: relative;
border: 5px solid red;
height: 500px;
width: 500px;
background: #f8f8f8;
padding: 30px;
}
.dtborder:before {
content: "";
position: absolute;
top: 5px;
bottom: 5px;
left: 5px;
right: 5px;
border: 5px solid blue;
}
.dtborder:after {
content: "";
position: absolute;
top: 15px;
bottom: 15px;
left: 15px;
right: 15px;
border: 5px solid green;
}
<div class="dtborder ">This text appears inside a double bracket bordered div where you can control the gap between border lines.</div>
See this : https://jsfiddle.net/kajh1odv/1/
You can consider linear-gradient that you can scale indefinitely to have as many border as you want. It may look complicated but you will see that all the gradient will have the same size (4px) so [100% 4px] for the horizontal ones and [4px 100%] for the vertical ones. Then for the position we remove/add 8px (or any value) each time to offest between each gradient.
.dtborder {
position: relative;
height: 200px;
width: 300px;
background:
/*First border*/
linear-gradient(red,red) 0 100%/100% 4px, /*Bottom*/
linear-gradient(red,red) 0 0/100% 4px , /*Top*/
linear-gradient(red,red) 0 0/4px 100% , /*left*/
linear-gradient(red,red) 100% 0/4px 100%, /*right*/
/*Second border*/
linear-gradient(blue,blue) 0 calc(100% - 8px)/100% 4px ,
linear-gradient(blue,blue) 0 8px/100% 4px,
linear-gradient(blue,blue) 8px 0/4px 100%,
linear-gradient(blue,blue) calc(100% - 8px) 0/4px 100%,
/*third border*/
linear-gradient(green,green) 0 calc(100% - 16px)/100% 4px,
linear-gradient(green,green) 0 16px/100% 4px,
linear-gradient(green,green) 16px 0/4px 100%,
linear-gradient(green,green) calc(100% - 16px) 0/4px 100%;
/*And so on ...*/
background-repeat:no-repeat;
padding: 30px;
}
<div class="dtborder ">This text appears inside a double bracket bordered div where you can control the gap between border lines.</div>
You can optimize the code like this:
.dtborder {
position: relative;
height: 200px;
width: 300px;
background:
/*First border*/
linear-gradient(red,red) 0 100%,
linear-gradient(red,red) 0 0,
linear-gradient(red,red) 0 0,
linear-gradient(red,red) 100% 0,
/*Second border*/
linear-gradient(blue,blue) 0 calc(100% - 8px),
linear-gradient(blue,blue) 8px 0,
linear-gradient(blue,blue) 0 8px,
linear-gradient(blue,blue) calc(100% - 8px) 0,
/*third border*/
linear-gradient(green,green) 0 calc(100% - 16px),
linear-gradient(green,green) 16px 0,
linear-gradient(green,green) 0 16px,
linear-gradient(green,green) calc(100% - 16px) 0;
/*And so on ...*/
background-size:100% 4px,4px 100%;
background-repeat:no-repeat;
padding: 30px;
}
<div class="dtborder ">This text appears inside a double bracket bordered div where you can control the gap between border lines.</div>
And also like this too:
.dtborder {
position: relative;
height: 200px;
width: 300px;
background:
/*First border*/
linear-gradient(red,red) left 0 bottom 0,
linear-gradient(red,red) 0 0,
linear-gradient(red,red) 0 0,
linear-gradient(red,red) right 0 top 0,
/*Second border*/
linear-gradient(blue,blue) left 0 bottom 8px,
linear-gradient(blue,blue) 8px 0,
linear-gradient(blue,blue) 0 8px,
linear-gradient(blue,blue) right 8px top 0,
/*third border*/
linear-gradient(green,green) left 0 bottom 16px,
linear-gradient(green,green) 16px 0,
linear-gradient(green,green) 0 16px,
linear-gradient(green,green) right 16px top 0;
/*And so on ...*/
background-size:100% 4px,4px 100%;
background-repeat:no-repeat;
padding: 30px;
}
<div class="dtborder ">This text appears inside a double bracket bordered div where you can control the gap between border lines.</div>
Here I try to figure out some thing like your image, hope this approach help you..thanks
.dtborder {
position: relative;
border: 5px solid red;
height: 500px;
width: 500px;
background: #f8f8f8;
padding: 30px;
overflow: hidden;
}
.dtborder:before {
content: "";
position: absolute;
top: 5px;
left: 0;
width: 100%;
height: 5px;
background: blue;
}
.dtborder:after {
content: "";
position: absolute;
top: 0;
left: 5px;
width: 5px;
height: 100%;
background: blue;
}
.dtborder_two:before {
content: "";
position: absolute;
top: 0;
right: 5px;
width: 5px;
height: 100%;
background: blue;
}
.dtborder_two:after {
content: "";
position: absolute;
bottom: 5px;
right: 0;
width: 100%;
height: 5px;
background: blue;
}
.dtborder_three:before {
content: "";
position: absolute;
top: 0;
right: 15px;
width: 5px;
height: 100%;
background: #36648b;
}
.dtborder_three:after {
content: "";
position: absolute;
bottom: 15px;
right: 0;
width: 100%;
height: 5px;
background: #36648b;
}
.dtborder_four:before {
content: "";
position: absolute;
top: 15px;
left: 0;
width: 100%;
height: 5px;
background: #36648b;
}
.dtborder_four:after {
content: "";
position: absolute;
top: 0;
left: 15px;
width: 5px;
height: 100%;
background: #36648b;
}
<div class="dtborder">
<div class="dtborder_two">
<div class="dtborder_three">
<div class="dtborder_four">
This text appears inside a double bracket bordered div where you can control the gap between border lines.
</div>
</div>
</div>
</div>
Trying to create a transparent triangle div with a colored border.
css
#down {
display: block;
position: fixed;
left: 0; right: 0;
width: 0; height: 0;
margin: 0 auto;
border-left: 55px solid transparent;
border-right: 55px solid transparent;
z-index: 20;
bottom: 0;
border-bottom: 55px solid rgba(250,250,250,0.75);
}
putting a div on-top another div ruins the transparency
You can also use gradients and/or transform:
on left: square + border-top/left + transform + gradient to draw the bottom border:
on middle : yours
on right : border-bottom + gradient for the triangle top borders
both extra example can hold content such as font icone / text / image .
body {
background:tomato;
}
#rotate {
position:fixed;
border:solid turquoise;
border-bottom:none;
border-right:none;
bottom:7px;
left:calc(50% - 180px);
height:75px;
width:75px;
transform-origin: bottom left;
transform:rotate(45deg);
background:linear-gradient(to bottom right, transparent calc(50% - 3px), turquoise calc(50% - 3px), turquoise 50%, transparent 50% );
}
#bg-gradient {
position:fixed;
bottom:5px;
left: calc(50% + 70px) ;
border-bottom:solid turquoise;
background:linear-gradient(to bottom right, transparent 50%, turquoise 50%, turquoise calc(50% + 3px), transparent calc(50% + 3px) ),linear-gradient(to bottom left, transparent 50%, turquoise 50%, turquoise calc(50% + 3px), transparent calc(50% + 3px) ) right
;
background-repeat:no-repeat;
background-size:50% 100%;
height:55px;
width:110px;
}
#down {
display: block;
position: fixed;
left: 0; right: 0;
width: 0; height: 0;
margin: 0 auto;
border-left: 55px solid transparent;
border-right: 55px solid transparent;
z-index: 20;
bottom: 5px;
border-bottom: 55px solid rgba(250,250,250,0.75);
}
<div id="down"></div>
<div id="rotate"></div>
<div id="bg-gradient"></div>
Notice that a rotated square at bottom can have half being hidden
This is usually done with border tricks, and those are not really helpful for this
You need others techniques for that.
For instance, see this CSS
body {
background: linear-gradient(90deg, lightblue, yellow)
}
.trapezoid {
left: 50px;
top: 50px;
position: absolute;
height: 100px;
width: 500px;
background-color: transparent;
}
.trapezoid:before {
content: '';
width: 57%;
height: 100%;
left: -4%;
position: absolute;
border-color: red;
border-style: solid;
border-width: 3px 0px 3px 3px;
-webkit-transform: skewX(-20deg);
}
.trapezoid:after {
content: '';
width: 59%;
height: 100%;
right: -4%;
position: absolute;
border-color: red;
border-style: solid;
border-width: 3px 3px 3px 0px;
-webkit-transform: skewX(20deg);
}
This is a very easy solution, but it uses CSS transform which isn't supported by IE lower than 9.0.
Remember that this triangle is at the very bottom of the page, so a rotated square can be used.
#down {
display: block;
position: fixed;
left: 0; right: 0;
bottom: -47px;
width: 80px;
height: 80px;
margin: 0 auto;
border: 0;
z-index: 20;
background-color: rgba(250,250,250,0.75);
-ms-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
border: 3px solid #ffaa33;
}
#down-inner { /* Must be rotated back */
width: 100%;
height: 100%;
-ms-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
}
body {
background-color: #e7e7e7;
color: #444444;
font-family: Arial, sans-serif;
}
<div id="down">
<div id="down-inner">A rotated square</div>
</div>
I was able to resolve this with fewer lines of code.
body {
background: url(https://images.unsplash.com/photo-1500390365106-166bb67248d6?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2434&q=80) no-repeat top; background-size: cover;
min-height: 300px;
}
.triangle {
position: absolute;
top: 25%;
left: 30%;
height: 158px;
width: 182px;
background: white;
clip-path: polygon(50% 0%, 0% 100%, 1.75% 100%, 50% 3%, 97.5% 98.35%, 1.75% 98.35%, 1.75% 100%, 100% 100%);
}
<div class="triangle"></div>
The hexagon version is also shown here:
https://codepen.io/smeyer/pen/gOPmxqm
You can play with the numbers to alter the border width.