How to create a triple overlapping border with CSS? - html

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>

Related

Mixing two colors for a background in CSS

I want to stack two colors one on top of the other. I did it by creating and sovrapposing two divs, having the one on the top with an opacity of 60%.
I wonder if there's a simpler way requiring only one div with two colors or maybe just one color that is a mix of the two.
I post here my code, If you notice any bad practice let me know please. I am eager to improve my skills.
* {
padding: 0;
margin: 0;
border: 0;
box-sizing: border-box;
}
/* ~~~~~~~~~~SKY~~~~~~~~~~ */
#sky {
position: relative;
z-index: -100;
width: 100vw;
height: 100vh;
background-image: linear-gradient( to top, midnightblue, black);
}
/* ~~~~~~~~~~MOON~~~~~~~~~~ */
.moon {
position: absolute;
top: 3%;
right: 0%;
width: 200px;
height: 200px;
border-radius: 50%;
}
#dark-moon {
background-color: silver;
}
#light-moon {
background-color: goldenrod;
background-image: radial-gradient(dimgrey 20%, transparent 16%), radial-gradient(dimgrey 15%, transparent 16%);
background-size: 60px 60px;
background-position: 0 0, 30px 30px;
opacity: 60%;
}
/* ~~~~~~~~~~SEA~~~~~~~~~~ */
#sea {
position: absolute;
bottom: 0%;
width: 100vw;
height: 25vh;
background-color: #48B;
}
<div id="sky">
<div id="dark-moon" class="moon"></div>
<div id="light-moon" class="moon"></div>
</div>
<div id="sea"></div>
As you can see there's a golden moon over a silver one. How can I get the same result having only one moon?
You can do it with 0 elements using pseudo element and multiple backgrounds:
html {
min-height: 100%;
background: linear-gradient( to top, midnightblue, black);
}
html::before {
content:"";
position: absolute;
top: 3%;
right: 0;
width: 200px;
height: 200px;
border-radius: 50%;
background:
linear-gradient(rgba(192,192,192,0.4) 0 0),
radial-gradient(dimgrey 20%, transparent 16%),
radial-gradient(dimgrey 15%, transparent 16%) 30px 30px,
goldenrod;
background-size: 60px 60px;
}
html::after {
content:"";
position: absolute;
bottom: 0;
left:0;
right:0;
height: 25vh;
background: #48B;
}
Another fancy idea to optimize the code more:
html {
min-height: 100%;
background:
linear-gradient(#48B 0 0) bottom/100% 25vh no-repeat fixed,
linear-gradient(black,midnightblue);
}
html::before {
content:"";
position: absolute;
top: 3%;
right: 0;
width: 200px;
height: 200px;
border-radius: 50%;
background:
linear-gradient(#48B 0 0) bottom/100% 25vh no-repeat fixed,
linear-gradient(rgba(192,192,192,0.4) 0 0),
radial-gradient(dimgrey 20%, transparent 16%) 0 0 /60px 60px,
radial-gradient(dimgrey 15%, transparent 16%) 30px 30px/60px 60px,
goldenrod;
}
Another option that only involves setting one background property would be to "stretch and displace" a linear-gradient in such a way that the result is a single color.
--base-col and --blend-col defines the gradient, --blend-amount sets the color mix, and --stretch-factor determines how much stretch is applied to the gradient:
* {
padding: 0;
margin: 0;
border: 0;
box-sizing: border-box;
}
/* ~~~~~~~~~~SKY~~~~~~~~~~ */
#sky {
position: relative;
z-index: -100;
width: 100vw;
height: 100vh;
background-image: linear-gradient( to top, midnightblue, black);
}
/* ~~~~~~~~~~MOON~~~~~~~~~~ */
.moon {
position: absolute;
top: 3%;
right: 0%;
width: 200px;
height: 200px;
border-radius: 50%;
}
#dark-moon {
--blend-amount: 60%;
--base-col: silver;
--blend-col: goldenrod;
--stretch-factor: 100;
background: linear-gradient(
var(--base-col) calc(( 0% - var(--blend-amount)) * var(--stretch-factor)),
var(--blend-col) calc((100% - var(--blend-amount)) * var(--stretch-factor))
);
}
#light-moon {
background-image: radial-gradient(dimgrey 20%, transparent 16%), radial-gradient(dimgrey 15%, transparent 16%);
background-size: 60px 60px;
background-position: 0 0, 30px 30px;
}
/* ~~~~~~~~~~SEA~~~~~~~~~~ */
#sea {
position: absolute;
bottom: 0%;
width: 100vw;
height: 25vh;
background-color: #48B;
}
<div id="sky">
<div id="dark-moon" class="moon"></div>
<div id="light-moon" class="moon"></div>
</div>
<div id="sea"></div>
You can try to get the hex code for the mixed color first using online color mixer tool such as this one https://colordesigner.io/color-mixer. After that you can use the result color in one div.

Css Shadow box ::after arrox with border method

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>

How to get a partial circle border around an image?

I want to design the following for displaying profile picture. I tried using border-style: dashed, but that's not what I want; I want only three lines (dashes) in the border. How can I accomplish this?
Here's what I tried:
#circle {
border-radius: 100%;
width: 100px;
height: 100px;
border: 5px dashed;
background-color: yellow;
}
<!DOCTYPE html>
<html>
<body>
<div id="circle"></div>
</body>
</html>
The effect I desire:
Here is an idea with multiple background:
#circle {
border-radius: 100%;
width: 100px;
height: 100px;
border: 5px solid transparent; /* Control the thickness*/
background:
url(https://picsum.photos/id/100/200/200) center/cover content-box,
linear-gradient(blue,blue) top /100% 20% border-box,
linear-gradient(blue,blue) bottom left /35% 50% border-box,
linear-gradient(blue,blue) bottom right/35% 50% border-box;
background-repeat:no-repeat;
}
<div id="circle"></div>
If you want space between image and border add an extra layer:
#circle {
border-radius: 100%;
width: 100px;
height: 100px;
border: 5px solid transparent; /*Control the thickness*/
padding:3px; /*control the space*/
background:
url(https://picsum.photos/id/100/200/200) center/cover content-box,
linear-gradient(white,white) padding-box,
linear-gradient(blue,blue) top /100% 20% border-box,
linear-gradient(blue,blue) bottom left /35% 50% border-box,
linear-gradient(blue,blue) bottom right/35% 50% border-box;
background-repeat:no-repeat;
}
<div id="circle"></div>
I tried something like that, not sure if entirely fit your needs..but give it a try, maybe it's a good starting point for you. Play with the numbers from css file and maybe you got exactly what you need.
Codesandbox here: https://codesandbox.io/s/vibrant-glade-uo7bg
.circle {
width: 80px;
height: 80px;
border-radius: 50%;
background-color: gray;
position: relative;
}
#shadow-1 {
position: absolute;
top: -1px;
left: -1px;
width: 85px;
height: 85px;
transform: rotate(-20deg);
border-radius: 50%;
box-shadow: 5px 5px 0 -4px blue;
}
#shadow-2 {
position: absolute;
top: -5px;
left: -2.5px;
transform: rotate(-40deg);
width: 85px;
height: 85px;
border-radius: 50%;
box-shadow: 5px -5px 0 -4px blue;
}
#shadow-3 {
position: absolute;
top: -1px;
left: -4px;
width: 85px;
height: 85px;
transform: rotate(20deg);
border-radius: 50%;
box-shadow: -5px 5px 0 -4px blue;
}
<h1>Hello Circle!</h1>
<div>
<div class="circle">
<div id="shadow-1"></div>
<div id="shadow-2"></div>
<div id="shadow-3"></div>
</div>
</div>

How can I correctly add a shadow and a gradient to my triangular shape?

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>

transparent triangle with border

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.