I'm trying to get 4 circles within in each other (that don't have a background colour, just a border colour) with text inside the last one using CSS.
Example: http://imgur.com/a/5vUKI
Any idea on how this can be done?
Here you go. This should help you get started.
.circle {
border-radius: 50%;
background: transparent;
border: 2px solid red;
width: 500px;
height: 500px;
margin: 0 auto;
display: flex;
justify-content: center;
align-items: center;
}
.c2 {
width: 400px;
height: 400px;
border-color: blue;
}
.c3 {
width: 300px;
height: 300px;
border-color: yellow;
}
.c4 {
width: 200px;
height: 200px;
}
<div class="circles">
<div class="circle c1">
<div class="circle c2">
<div class="circle c3">
<div class="circle c4"></div>
</div>
</div>
</div>
</div>
It's a styling, so don't mess with inner HTML code. CSS Gradients can do this well. it's even animatable
.container {
display: inline-block;
height: 12em;
width: 12em;
padding: 4em;
text-align: center;
background: radial-gradient(circle closest-side,
hsla( 0, 80%, 80%, 0) 0%,
hsla( 0, 80%, 80%, 0) 78%,
hsla( 0, 80%, 80%, 1) 79%,
hsla( 0, 80%, 80%, 1) 82%,
hsla( 0, 80%, 80%, 0) 83%,
hsla(100, 80%, 80%, 0) 87%,
hsla(100, 80%, 80%, 1) 88%,
hsla(100, 80%, 80%, 0) 89%,
hsla(200, 80%, 80%, 0) 92%,
hsla(200, 80%, 80%, 1) 93%,
hsla(200, 80%, 80%, 0) 94%,
hsla(300, 80%, 80%, 0) 97%,
hsla(300, 80%, 80%, 1) 98%,
hsla(300, 80%, 80%, 0) 99%
)
;
}
<div class="container">
My inner text is here
</div>
Simply position all the circles on top of each other.
#outer-circle {
border: 1px solid red;
border-radius: 50%;
height: 500px;
width: 500px;
position: relative;
text-align: center;
}
#inner-circle {
position: absolute;
border: 1px solid red;
border-radius: 50%;
height: 480px;
width: 480px;
top: 50%;
left: 50%;
margin: -240px 0px 0px -240px;
}
#inner-circle2 {
position: absolute;
border: 1px solid red;
border-radius: 50%;
height: 460px;
width: 460px;
top: 50%;
left: 50%;
margin: -230px 0px 0px -230px;
}
#inner-circle3 {
position: absolute;
border: 1px solid red;
border-radius: 50%;
height: 440px;
width: 440px;
top: 50%;
left: 50%;
margin: -220px 0px 0px -220px;
}
#text {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-o-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
<div id="outer-circle">
<div id="inner-circle">
<div id="inner-circle2">
<div id="inner-circle3">
<div id="text">Breathe out</div>
</div>
</div>
</div>
</div>
Here's my version.
My logic was divided into 2 steps:
Step One :
The .circle-1 is set as relative to be the container of the child's div.
Step Two
The rest of the div's is set as absolute and has a smallest padding that their father, for their parent aways be bigger than the son.
The align in x-axis is set by the left and right as 0 and margin as 0 auto.
The align in y-axis is set by the top:50% and transform:translateY(-50%).
div{
position: absolute;
border: 3px solid;
border-radius: 50%;
width: 150px;
height: 150px;
left:0;
right:0;
top: 50%;
transform: translateY(-50%);
margin:0 auto;
}
.circle-1{
top: 200px;
padding: 40px;
position: relative;
}
.circle-2{
padding: 30px;
border-color: blue;
}
.circle-3{
padding: 20px;
}
.circle-4{
padding: 10px;
}
<div class="circle-1">
<div class="circle-2">
<div class="circle-3">
<div class="circle-4"></div>
</div>
</div>
</div>
Messing around with this as I procrastinated.
Vertically responsive, basic hover effect.
html, body {
display: flex;
justify-content: center;
height: 100vh;
margin: 0;
padding: 0;
background-color: gray;
}
div {
display: flex;
flex-grow: 1;
background-color: hsla(0, 0%, 0%, 0.0);
border-style: solid;
border-color: white;
border-width: 5px;
border-radius: 100%;
padding: 5px;
overflow: hidden;
transition: all 0.1s linear;
box-sizing: border-box;
}
.ring1 {
height: 100vh;
width: calc(100vh);
}
.ring2 {
border-color: royalblue;
}
.ring4 {
justify-content: center;
align-items: center;
text-align: center;
font-size: 28px;
font-variant: small-caps;
font-weight: bold;
color: royalblue;
background-color: salmon;
}
.ring1:hover, .ring1:hover div {
padding: 3px;
font-size: 32px;
border-width: 3px;
}
<div class="ring1">
<div class="ring2">
<div class="ring3">
<div class="ring4">
Breathe Out
</div>
</div>
</div>
</div>
fiddle
https://jsfiddle.net/Hastig/9v4mLdep/
Related
I know there are many different ways to draw in CSS but I want to draw this shape using CSS ::before and ::after pseudo-elements.
Only the yellow part I could not draw it.
.body{
width:100%;
height:100%;
background:#191919;
display: flex;
justify-content: center;
align-items: center;
}
.circle {
position: relative;
width: 160px;
height: 160px;
background: #824B20;
border-radius: 50%;
}
.circle::before{
content: "";
width: 100px;
height: 100px;
background: #E08027;
position: absolute;
border-radius: 50%;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
.circle::after{
content:"";
/*color : #FFF58F */
}
<div class="body"><div class="circle";div><div><div>
An idea using only gradients:
.box {
width: 200px;
aspect-ratio:1;
border-radius: 50%;
background:
radial-gradient(circle at 78% 50%, yellow 4%,#0000 4.5%),
radial-gradient(circle at 22% 50%, yellow 4%,#0000 4.5%),
radial-gradient(at top,#0000 33%,yellow 34% 45%,#0000 46%)
bottom/100% 50% no-repeat,
radial-gradient(#E08027 40%,#824B20 41%);
}
<div class="box"></div>
.body {
width: 100%;
height: 100vh;
background: #191919;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
.circle {
box-sizing: border-box;
position: relative;
width: 160px;
height: 160px;
background: #E08027;
border: 30px solid #824B20;
border-radius: 50%;
}
.half-circle {
position: absolute;
width: 85px;
height: 85px;
border: 14px solid #FFF58F;
border-top-color: transparent;
border-left-color: transparent;
border-radius: 50%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) rotate(45deg);
}
.half-circle::before,
.half-circle::after {
content: "";
position: absolute;
top: 69px;
width: 14px;
height: 14px;
border-radius: 50%;
background: #FFF58F;
}
.half-circle::before {
left: 0;
}
.half-circle::after {
left: 71px;
transform: translate(-2px, -70px);
}
<div class="body">
<div class="circle">
<div class="half-circle"></div>
</div>
</div>
does anyone know how I can center the white circle into to middle of the blue circle and set the white circle above all other elements? I tried with relative and absolute positioning and with the z-index but I couldnt get it to work. I'm kinda a noob in CSS
.start-container {
height: 100vh;
display: grid;
grid-template-rows: 20% 65% 15%;
grid-template-areas: "header" "startpage" "footer";
}
.header {}
.header-shape {
height: 100%;
background-color: blue;
clip-path: polygon(0 60%, 100% 40%, 100% 100%, 0% 100%);
}
.profile-shape {
position: absolute;
top: 7vw;
left: 65vw;
width: 10vw;
height: 10vw;
background-color: blue;
border-radius: 50%;
filter: drop-shadow(0px 3px 30px rgba(0, 0, 0, 0.60));
}
.profile-picture {
width: 90%;
height: 90%;
background-color: white;
border-radius: 50%;
position: absolute;
top: 50%;
left: 50%;
margin: -50% 0 0 -50%;
}
.startpage {}
.footer {
background-color: yellow;
}
<div class="start-container">
<div class="header">
<div class="profile-shape">
<div class="profile-picture"></div>
</div>
<div class="header-shape"></div>
</div>
<div class="startpage"></div>
<div class="footer"></div>
</div>
If you give your shape a z-index, it will put it on top. Make it flex with justify-content and align-items center and that will centre your profile (after removing the absolute positioning):
.start-container {
height: 100vh;
display: grid;
grid-template-rows: 20% 65% 15%;
grid-template-areas: "header" "startpage" "footer";
}
.header {}
.header-shape {
height: 100%;
background-color: blue;
clip-path: polygon(0 60%, 100% 40%, 100% 100%, 0% 100%);
}
.profile-shape {
position: absolute;
top: 7vw;
left: 65vw;
width: 10vw;
height: 10vw;
background-color: blue;
border-radius: 50%;
filter: drop-shadow(0px 3px 30px rgba(0, 0, 0, 0.60));
display: flex;
align-items: center;
justify-content: center;
z-index: 1;
}
.profile-picture {
width: 90%;
height: 90%;
background-color: white;
border-radius: 50%;
}
.startpage {}
.footer {
background-color: yellow;
}
<div class="start-container">
<div class="header">
<div class="profile-shape">
<div class="profile-picture"></div>
</div>
<div class="header-shape"></div>
</div>
<div class="startpage"></div>
<div class="footer"></div>
</div>
Per comment, if you want blue circle (changed to red in example below) below and white above, you would need to have an extra object otherwise the white circle will always be on the same stacking context as it's parent:
.start-container {
height: 100vh;
display: grid;
grid-template-rows: 20% 65% 15%;
grid-template-areas: "header" "startpage" "footer";
}
.header {}
.header-shape {
height: 100%;
background-color: blue;
clip-path: polygon(0 60%, 100% 40%, 100% 100%, 0% 100%);
}
.profile-placement {
position: absolute;
top: 7vw;
left: 65vw;
width: 10vw;
height: 10vw;
}
.profile-placement--shape {
background-color: red;
border-radius: 50%;
filter: drop-shadow(0px 3px 30px rgba(0, 0, 0, 0.60));
}
.profile-placement--picture {
display: flex;
align-items: center;
justify-content: center;
z-index: 1;
}
.profile-picture {
width: 90%;
height: 90%;
background-color: white;
border-radius: 50%;
}
.startpage {}
.footer {
background-color: yellow;
}
<div class="start-container">
<div class="header">
<div class="profile-placement profile-placement--shape">
</div>
<div class="profile-placement profile-placement--picture">
<div class="profile-picture"></div>
</div>
<div class="header-shape"></div>
</div>
<div class="startpage"></div>
<div class="footer"></div>
</div>
Just adjust the margin with the remaining height and width on the profile-picture class.
The remaining size is 10% height and 10% weight. So there will be +5%(-45%) on the left margin and +5%(-45%) on the top margin. It will make the circle center
.start-container{
height: 100vh;
display: grid;
grid-template-rows: 20% 65% 15%;
grid-template-areas:
"header"
"startpage"
"footer"
;
}
.header{
}
.header-shape{
height: 100%;
background-color: blue;
clip-path: polygon(0 60%, 100% 40%, 100% 100%, 0% 100%);
}
.profile-shape{
position: absolute;
top: 7vw;
left: 65vw;
width: 10vw;
height: 10vw;
background-color: blue;
border-radius: 50%;
filter: drop-shadow(0px 3px 30px rgba(0,0,0,0.60));
}
.profile-picture{
width: 90%;
height: 90%;
background-color: white;
border-radius: 50%;
position: absolute;
top: 50%;
left: 50%;
margin: -45% 0 0 -45%;
}
.startpage{
}
.footer{
background-color: yellow;
}
<div class="start-container">
<div class="header">
<div class="profile-shape">
<div class="profile-picture"></div>
</div>
<div class="header-shape"></div>
</div>
<div class="startpage"></div>
<div class="footer"></div>
</div>
I am trying to style this arrow but i have been unable to get this exact style.
here is image of what i want to achieve
here is image of what i am getting
HTML Code:
<div className="arrow-div">
<p>2. Summary</p>
</div>
CSS Code:
.arrow-div {
width: 209px;
height: 56px;
display: inline-flex;
margin: 54px 10px;
border: 1px solid #d2d6dc;
clip-path: polygon(75% 0%, 84% 50%, 75% 100%, 0% 100%, 9% 53%, 0% 0%);
padding: 18px 3px 18px 32px;
}
.arrow-div {
height: 50px;
width: 100px;
padding-left: 20px;
display: inline-block;
position: relative;
margin-left: 20px;
}
.arrow-div:before,
.arrow-div:after {
content: '';
left: -15px;
position: absolute;
height: 23px;
width: 132px;
border-left: 2px solid #0f3c80;
border-right: 2px solid #0f3c80;
}
.arrow-div:before {
border-top: 2px solid #0f3c80;
transform-origin: 0% 0%;
transform: skewX(30deg);
top: 0;
}
.arrow-div:after {
border-bottom: 2px solid #0f3c80;
transform-origin: 0% 100%;
transform: skewX(-30deg);
bottom: 0;
}
p {
color: #0f3c80;
<div class="arrow-div">
<p>2. Summary</p>
</div>
Having the following code snippet:
body {
background-color: #9fd8ee;
}
.tree {
display: flex;
flex-direction: column;
align-items: center;
}
.triangle-one {
width: 0;
height: 0;
border-left: 60px solid transparent;
border-right: 60px solid transparent;
border-bottom: 100px solid rgb(20, 97, 27);
margin-top: -69px;
}
.triangle-two {
width: 0;
height: 0;
border-left: 90px solid transparent;
border-right: 90px solid transparent;
border-bottom: 150px solid rgb(20, 97, 27);
margin-top: -40px;
}
.triangle-three {
width: 0;
height: 0;
border-left: 120px solid transparent;
border-right: 120px solid transparent;
border-bottom: 200px solid rgb(20, 97, 27);
margin-top: -80px;
}
.triangle-four {
width: 0;
height: 0;
border-left: 150px solid transparent;
border-right: 150px solid transparent;
border-bottom: 250px solid rgb(20, 97, 27);
margin-top: -120px;
}
.rectangle {
height: 50px;
width: 60px;
background-color: maroon;
}
.globe {
border-radius: 50%;
width: 25px;
height: 25px;
position: absolute;
}
.glpos-1 {
background: red;
top: 175px;
left: 630px;
}
.glpos-2 {
background: blue;
top: 225px;
left: 655px;
}
.glpos-3 {
background: yellow;
top: 315px;
left: 610px;
}
.glpos-4 {
background: orange;
top: 375px;
left: 680px;
}
.glpos-5 {
background: cyan;
top: 425px;
left: 640px;
}
.glpos-6 {
background: red;
top: 535px;
left: 700px;
}
.glpos-7 {
background: blue;
top: 510px;
left: 590px;
}
.light {
border-radius: 50%;
width: 10px;
height: 10px;
background: yellow;
animation: example 1s infinite;
position: absolute;
}
.lipos-1 {
top: 260px;
left: 620px;
}
.lipos-2 {
top: 300px;
left: 710px;
}
.lipos-3 {
top: 410px;
left: 590px;
}
.lipos-4 {
top: 510px;
left: 730px;
}
.lipos-5 {
top: 160px;
left: 666px;
}
.lipos-6 {
top: 417px;
left: 700px;
}
.lipos-7 {
top: 480px;
left: 610px;
}
#keyframes example {
50% {
box-shadow: 1px 1px 10px #ccc, -2px 1px 10px #ccc, 0 -1px 10px #ccc;
}
}
.star {
margin: 50px 0;
position: relative;
display: block;
color: yellow;
width: 0px;
height: 0px;
border-right: 100px solid transparent;
border-bottom: 70px solid yellow;
border-left: 100px solid transparent;
transform: rotate(35deg) scale(0.75);
}
.star:before {
border-bottom: 80px solid yellow;
border-left: 30px solid transparent;
border-right: 30px solid transparent;
position: absolute;
height: 0;
width: 0;
top: -45px;
left: -65px;
display: block;
content: '';
transform: rotate(-35deg);
}
.star:after {
position: absolute;
display: block;
color: yellow;
top: 3px;
left: -105px;
width: 0px;
height: 0px;
border-right: 100px solid transparent;
border-bottom: 70px solid yellow;
border-left: 100px solid transparent;
transform: rotate(-70deg);
content: '';
}
<!DOCTYPE html>
<html>
<head>
<title>Christmas tree</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div class="tree">
<div class="star"></div>
<div class="triangle-one"></div>
<div class="triangle-two"></div>
<div class="triangle-three"></div>
<div class="triangle-four"></div>
<div class="rectangle"></div>
</div>
<div class="globe glpos-1"></div>
<div class="globe glpos-2"></div>
<div class="globe glpos-3"></div>
<div class="globe glpos-4"></div>
<div class="globe glpos-5"></div>
<div class="globe glpos-6"></div>
<div class="globe glpos-7"></div>
<div class="light lipos-1"></div>
<div class="light lipos-2"></div>
<div class="light lipos-3"></div>
<div class="light lipos-4"></div>
<div class="light lipos-5"></div>
<div class="light lipos-6"></div>
<div class="light lipos-7"></div>
</body>
</html>
When the Dev tools is opened, the width of the window is around 1200px and in that case all the globes and lights are situated on the tree.
How can they be changed in order to be on the tree no mater the width of the window?
Why not a different idea with less of code and responsive. I picked the clip-path of the star from here: https://bennettfeely.com/clippy/
.tree {
max-width:300px;
margin:auto;
position:relative;
/* the bottom of the tree */
border-bottom:50px solid transparent;
background:linear-gradient(maroon 0 0) bottom/20% 50px no-repeat border-box;
}
.tree div {
padding-top:200%; /* keep it responsive at the same ratio */
}
.tree::before { /* the star */
content:"";
position:absolute;
z-index:1;
top: 10%;
left: 25%;
width: 50%;
height: 25%;
background:yellow;
clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}
.tree > div::before,
.tree > div::after{ /* the main part of the tree */
content:"";
position:absolute;
top:0;
bottom:0;
width:25%;
padding-right: 25%;
--g:linear-gradient(to bottom right,transparent 49.5%,rgb(20, 97, 27) 50%) no-repeat;
background:
var(--g) -120% calc(0*100%/3),
var(--g) -70% calc(1*100%/3),
var(--g) -30% calc(2*100%/3),
var(--g) 0 calc(3*100%/3);
background-size:200% calc(100%/4 + 17%); /* update the 17% to control the shape */
background-origin: content-box;
}
.tree > div::after {
transform-origin:right;
transform:scaleX(-1);
}
.tree::after { /* the non animated globes */
content:"";
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
background:
/* color position: X Y*/
radial-gradient(farthest-side,red 98%,transparent ) 50% 30%,
radial-gradient(farthest-side,blue 98%,transparent ) 60% 70%,
radial-gradient(farthest-side,pink 98%,transparent ) 40% 50%,
radial-gradient(farthest-side,purple 98%,transparent ) 30% 90%;
background-size:8% 4%;
background-repeat:no-repeat;
}
i {
position: absolute;
border-radius: 50%;
width: 4%;
height: 2%;
background: yellow;
animation: ex 1s infinite;
}
#keyframes ex {
50% {box-shadow: 1px 1px 10px #ccc, -2px 1px 10px #ccc, 0 -1px 10px #ccc;}}
body {
background-color: #9fd8ee;
}
<div class="tree">
<div></div>
<i style="left:50%;bottom:10%"></i>
<i style="left:40%;bottom:30%"></i>
<i style="left:60%;bottom:50%"></i>
<i style="left:35%;bottom:60%"></i>
</div>
And here is many trees, enjoy!
.tree {
width:250px;
display:inline-block;
margin:0 5px;
position:relative;
/* the bottom of the tree */
border-bottom:50px solid transparent;
background:linear-gradient(maroon 0 0) bottom/20% 50px no-repeat border-box;
}
.tree div {
padding-top:200%; /* keep it responsive at the same ratio */
}
.tree::before { /* the star */
content:"";
position:absolute;
z-index:1;
top: 10%;
left: 25%;
width: 50%;
height: 25%;
background:yellow;
clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}
.tree > div::before,
.tree > div::after{ /* the main part of the tree */
content:"";
position:absolute;
top:0;
bottom:0;
width:25%;
padding-right: 25%;
--g:linear-gradient(to bottom right,transparent 49.5%,rgb(20, 97, 27) 50%) no-repeat;
background:
var(--g) -120% calc(0*100%/3),
var(--g) -70% calc(1*100%/3),
var(--g) -30% calc(2*100%/3),
var(--g) 0 calc(3*100%/3);
background-size:200% calc(100%/4 + var(--t,17%));
background-origin: content-box;
}
.tree > div::after {
transform-origin:right;
transform:scaleX(-1);
}
.tree::after { /* the non animated globes */
content:"";
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
background:
/* color position: X Y*/
radial-gradient(farthest-side,red 98%,transparent ) 50% 30%,
radial-gradient(farthest-side,blue 98%,transparent ) 60% 70%,
radial-gradient(farthest-side,pink 98%,transparent ) 40% 50%,
radial-gradient(farthest-side,purple 98%,transparent ) 30% 90%;
background-size:8% 4%;
background-repeat:no-repeat;
}
i {
position: absolute;
border-radius: 50%;
width: 4%;
height: 2%;
background: yellow;
animation: ex 1s infinite;
}
#keyframes ex {
50% {box-shadow: 1px 1px 10px #ccc, -2px 1px 10px #ccc, 0 -1px 10px #ccc;}}
body {
background-color: #9fd8ee;
}
<div class="tree">
<div></div>
<i style="left:50%;bottom:10%"></i>
<i style="left:40%;bottom:30%"></i>
<i style="left:60%;bottom:50%"></i>
<i style="left:35%;bottom:60%"></i>
</div>
<div class="tree" style="width:200px;--t:21%;">
<div></div>
<i style="left:50%;bottom:10%"></i>
<i style="left:40%;bottom:20%"></i>
<i style="left:60%;bottom:50%"></i>
<i style="left:50%;bottom:60%"></i>
</div>
<div class="tree" style="width:150px;--t:14%;">
<div></div>
</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>