what I want to do is to achieve the image with css, but I could not achieve exactly what I want. Thanks in advance for your help on how to do it.
.alt {
color: white;
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 130px;
background-color: #d2151e;
}
.alt:before {
content: ' ';
background: none;
display: block;
height: 0;
position: absolute;
width: 0;
top: 0;
left: 50%;
z-index: 99;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-top: 20px solid #ffffff;
}
.alt:after {
content: '';
}
<div class="alt flex">
<div class="flex w-full h-full item-center">
<div style="width: 40%">
</div>
</div>
<div class="logo">
</div>
</div>
Something like that ?
:root {
--card-width: 200px;
}
.container {
position: relative;
background-color: #E01D2B;
height: 180px;
width: 600px;
margin: auto;
overflow: hidden;
}
.arrow {
height: 100px;
width: 100%;
background-color: white;
display: flex;
justify-content: center;
align-items: flex-end;
}
.arrow::after {
display: block;
background-color: white;
width: 20px;
height: 20px;
bottom: 0;
content: '';
transform: translate(calc(var(--card-width) / -2), 50%) rotate(45deg);
}
.card {
display: block;
position: absolute;
bottom: 0;
right: 0;
width: calc(var(--card-width) + 40px);
height: 110px;
border-top-left-radius: 1em;
background-color: #eee;
transform: translate(34px) skewX(-30deg);
}
<div class="container">
<div class="arrow"></div>
<div class="card"></div>
</div>
Here is what you can do with css
.alt {
color: white;
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 130px;
background-color: #d2151e;
}
.alt:before {
content: ' ';
background: none;
display: block;
height: 0;
position: absolute;
width: 0;
top: 0;
left: 32%;
z-index: 99;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-top: 20px solid #ffffff;
}
.alt:after {
content: '';
}
.logo {
background: #f0f0f0;
width: 40%;
height: 160px;
position: absolute;
right: -100px;
box-shadow: -2px 1px 4px #757575c9;
top: -30px;
border-radius: 15px 0 0 0;
-webkit-transform: skew(-45deg);
-moz-transform: skew(-45deg);
-ms-transform: skew(-45deg);
transform: skew(-45deg);
overflow: hidden;
}
and html is
<div class="alt flex">
<div class="flex w-full h-full item-center">
<div style="width: 40%">
</div>
</div>
<div class="logo">
</div>
Related
I have this reindeer code, but it is very off center. I made this following a tutorial but in the tutorial it worked great but not on mine.
This is all the CCS code for the reindeer.
.reindeer {
height: 510px;
width: 350px;
position: absolute;
margin: auto;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.face {
background-color: #A98467;
height: 150px;
width: 100px;
border-radius: 70px;
position: relative;
top: 200px;
left: 320px;
}
.antler1, .antler2 {
height: 25px;
width: 96px;
border-right: 10px solid #6C584C;
border-top: 10px solid #6C584C;
border-radius: 0 20px 0 0;
z-index: -2;
position: relative;
bottom: 15px;
right: 65px;
}
.a1, .a2, .a3 {
background-color: #6C584C;
height: 55px;
width: 10px;
border-radius: 10px;
position: relative;
}
.a1 {
bottom: 55px;
}
.a2 {
bottom: 110px;
left: 30px;
}
.a3 {
bottom: 165px;
left: 60px;
}
.antler2 {
left: 65px;
bottom: 40px;
transform: rotateY(180deg);
}
.eye1, .eye2{
background-color: #333333;
height: 20px;
width: 20px;
border-radius: 50%;
position: relative;
}
.eye1 {
bottom: 5px;
left: 15px
}
.eye2 {
bottom: 25px;
left: 60px;
}
.eyeball {
background-color: white;
height: 8px;
width: 8px;
border-radius: 50%;
position: relative;
top: 5px;
left: 5px;
}
.ear1, .ear2 {
background-color: #95755E;
height: 30px;
width: 60px;
border-radius: 0 0 30px 30px;
position: relative;
z-index: -1;
}
.ear1 {
bottom: 75px;
right: 23px;
transform: rotate(-25deg);
}
.ear2 {
bottom: 105px;
left: 60px;
transform: rotate(25deg);
}
.nose {
background-color: #EE0000;
height: 22px;
width: 35px;
border-radius: 50%;
position: relative;
bottom: 60px;
left: 30px;
}
.nose2 {
background-color: #F8453B;
height: 9px;
width: 15px;
border-radius: 50%;
position: relative;
bottom: 78px;
left: 43px;
}
.leg1, .leg2 {
background-color: #6C584C;
height: 100px;
width: 20px;
position: relative;
border-radius: 0 0 8px 8px;
z-index: -2;
}
.leg1 {
left: 340px;
top: 300px;
}
.leg2 {
left: 380px;
top: 200px;
}
.body {
background-color: #95755E;
height: 200px;
width: 130px;
border-radius: 100px;
position: relative;
bottom: 60px;
left: 305px;
z-index: -1;
}
Im not sure how it made my reindeer so far off the center, I have tried changing relative to absolute, but it wont work. Anyone want to help me? This is a school project, and i need it done very fast.
https://imgur.com/a/rNKdyut
<div class="reindeer">
<div class="face">
<div class="antler1">
<div class="a1"></div>
<div class="a2"></div>
<div class="a3"></div>
</div>
<div class="antler2">
<div class="a1"></div>
<div class="a2"></div>
<div class="a3"></div>
</div>
<div class="eye1">
<div class="eyeball"></div>
</div>
<div class="eye2">
<div class="eyeball"></div>
</div>
<div class="ear1"></div>
<div class="ear2"></div>
<div class="nose"></div>
<div class="nose2"></div>
</div>
<div class="leg1"></div>
<div class="leg2"></div>
<div class="body"></div>
</div>
I found out something, but again same problem with it not being completely centered. I forgot to add the
height: 510px;
width: 350px;
position: absolute;
margin: auto;
top: 0;
bottom: 0;
left: 0;
right: 0;
in the .raindeer
And now it is more centered but i dont know how to make it more centered.
Excellent work on the styles for this. Rather than trying to make the reindeer centred - the simplest approach is to put the reindeer in a div and centre that - I am using 100vw and 100vh to make the container the full screen size - and then flex to align it to the vertical and horizontal centres.
UPDATE - I also adjusted your left positions of the different elements. You can also do this with flex - but to keep it as simple as possible - I just reduced the left values that you have.
Its bbest to view this in the full screen snippet - and again - damn fine work on the styling - I like what you have done :)
.wrapper {
height: 100vh;
width: 100vw;
display: flex;
align-items: center;
justify-content:center
}
.reindeer {
position: relative;
}
.face {
background-color: #A98467;
height: 150px;
width: 100px;
border-radius: 70px;
position: relative;
top: 200px;
left: 0;
}
.antler1, .antler2 {
height: 25px;
width: 96px;
border-right: 10px solid #6C584C;
border-top: 10px solid #6C584C;
border-radius: 0 20px 0 0;
z-index: -2;
position: relative;
bottom: 15px;
right: 70px;
}
.a1, .a2, .a3 {
background-color: #6C584C;
height: 55px;
width: 10px;
border-radius: 10px;
position: relative;
}
.a1 {
bottom: 55px;
}
.a2 {
bottom: 110px;
left: 30px;
}
.a3 {
bottom: 165px;
left: 60px;
}
.antler2 {
left: 65px;
bottom: 50px;
transform: rotateY(180deg);
}
.eye1, .eye2{
background-color: #333333;
height: 20px;
width: 20px;
border-radius: 50%;
position: relative;
}
.eye1 {
bottom: 5px;
left: 15px
}
.eye2 {
bottom: 25px;
left: 60px;
}
.eyeball {
background-color: white;
height: 8px;
width: 8px;
border-radius: 50%;
position: relative;
top: 5px;
left: 5px;
}
.ear1, .ear2 {
background-color: #95755E;
height: 30px;
width: 60px;
border-radius: 0 0 30px 30px;
position: relative;
z-index: -1;
}
.ear1 {
bottom: 75px;
right: 23px;
transform: rotate(-25deg);
}
.ear2 {
bottom: 105px;
left: 60px;
transform: rotate(25deg);
}
.nose {
background-color: #EE0000;
height: 22px;
width: 35px;
border-radius: 50%;
position: relative;
bottom: 60px;
left: 30px;
}
.nose2 {
background-color: #F8453B;
height: 9px;
width: 15px;
border-radius: 50%;
position: relative;
bottom: 78px;
left: 43px;
}
.leg1, .leg2 {
background-color: #6C584C;
height: 100px;
width: 20px;
position: relative;
border-radius: 0 0 8px 8px;
z-index: -2;
}
.leg1 {
left: 15px;
top: 300px;
}
.leg2 {
left: 55px;
top: 200px;
}
.body {
background-color: #95755E;
height: 200px;
width: 130px;
border-radius: 100px;
position: relative;
bottom: 60px;
left: -15px;
z-index: -1;
}
<div class="wrapper">
<div class="reindeer">
<div class="face">
<div class="antler1">
<div class="a1"></div>
<div class="a2"></div>
<div class="a3"></div>
</div>
<div class="antler2">
<div class="a1"></div>
<div class="a2"></div>
<div class="a3"></div>
</div>
<div class="eye1">
<div class="eyeball"></div>
</div>
<div class="eye2">
<div class="eyeball"></div>
</div>
<div class="ear1"></div>
<div class="ear2"></div>
<div class="nose"></div>
<div class="nose2"></div>
</div>
<div class="leg1"></div>
<div class="leg2"></div>
<div class="body"></div>
</div>
</div>
.header {
height: 100%;
width: 50%;
display: flex;
align-items: center;
justify-content:center
}
.reindeer {
position: relative;
}
.face {
background-color: #A98467;
height: 150px;
width: 100px;
border-radius: 70px;
position: relative;
top: 200px;
left: 320px;
}
.antler1, .antler2 {
height: 25px;
width: 96px;
border-right: 10px solid #6C584C;
border-top: 10px solid #6C584C;
border-radius: 0 20px 0 0;
z-index: -2;
position: relative;
bottom: 15px;
right: 65px;
}
.a1, .a2, .a3 {
background-color: #6C584C;
height: 55px;
width: 10px;
border-radius: 10px;
position: relative;
}
.a1 {
bottom: 55px;
}
.a2 {
bottom: 110px;
left: 30px;
}
.a3 {
bottom: 165px;
left: 60px;
}
.antler2 {
left: 65px;
bottom: 40px;
transform: rotateY(180deg);
}
.eye1, .eye2{
background-color: #333333;
height: 20px;
width: 20px;
border-radius: 50%;
position: relative;
}
.eye1 {
bottom: 5px;
left: 15px
}
.eye2 {
bottom: 25px;
left: 60px;
}
.eyeball {
background-color: white;
height: 8px;
width: 8px;
border-radius: 50%;
position: relative;
top: 5px;
left: 5px;
}
.ear1, .ear2 {
background-color: #95755E;
height: 30px;
width: 60px;
border-radius: 0 0 30px 30px;
position: relative;
z-index: -1;
}
.ear1 {
bottom: 75px;
right: 23px;
transform: rotate(-25deg);
}
.ear2 {
bottom: 105px;
left: 60px;
transform: rotate(25deg);
}
.nose {
background-color: #EE0000;
height: 22px;
width: 35px;
border-radius: 50%;
position: relative;
bottom: 60px;
left: 30px;
}
.nose2 {
background-color: #F8453B;
height: 9px;
width: 15px;
border-radius: 50%;
position: relative;
bottom: 78px;
left: 43px;
}
.leg1, .leg2 {
background-color: #6C584C;
height: 100px;
width: 20px;
position: relative;
border-radius: 0 0 8px 8px;
z-index: -2;
}
.leg1 {
left: 340px;
top: 300px;
}
.leg2 {
left: 380px;
top: 200px;
}
.body {
background-color: #95755E;
height: 200px;
width: 130px;
border-radius: 100px;
position: relative;
bottom: 60px;
left: 305px;
z-index: -1;
}
<div class="header">
<div class="reindeer">
<div class="face">
<div class="antler1">
<div class="a1"></div>
<div class="a2"></div>
<div class="a3"></div>
</div>
<div class="antler2">
<div class="a1"></div>
<div class="a2"></div>
<div class="a3"></div>
</div>
<div class="eye1">
<div class="eyeball"></div>
</div>
<div class="eye2">
<div class="eyeball"></div>
</div>
<div class="ear1"></div>
<div class="ear2"></div>
<div class="nose"></div>
<div class="nose2"></div>
</div>
<div class="leg1"></div>
<div class="leg2"></div>
<div class="body"></div>
</div>
</div>
It's all to do with you setting the left properties in your CSS. If you reduce these to shift the reindeer bits to just occupy the reindeer div you can then set the reindeer width to fit-content then use margin: auto to position it in the center of your screen.
Here's a couple of good videos by Kevin Powell on positioning here and here.
An explainer on how to use margin to center elements can be found on CSS tricks
If you like this sort of thing then try some of the challenges at CSS battle. It'll really sharpen your skills up.
Nice reindeer btw.
.pos {
/*this is used to draw a centerline down the screen. Feel free to delete this*/
position: fixed;
width: 50%;
height: 700px;
border-right: 1px solid red;
}
.reindeer {
/*position: relative; removed this */
width: fit-content; /* added this */
margin: auto; /* added this */
}
.face {
background-color: #a98467;
height: 150px;
width: 100px;
border-radius: 70px;
position: relative;
top: 200px;
left: 22px; /* reduced this */
}
.antler1,
.antler2 {
height: 25px;
width: 96px;
border-right: 10px solid #6c584c;
border-top: 10px solid #6c584c;
border-radius: 0 20px 0 0;
z-index: -2;
position: relative;
bottom: 15px;
right: 65px;
}
.a1,
.a2,
.a3 {
background-color: #6c584c;
height: 55px;
width: 10px;
border-radius: 10px;
position: relative;
}
.a1 {
bottom: 55px;
}
.a2 {
bottom: 110px;
left: 30px;
}
.a3 {
bottom: 165px;
left: 60px;
}
.antler2 {
left: 65px;
bottom: 40px;
transform: rotateY(180deg);
}
.eye1,
.eye2 {
background-color: #333333;
height: 20px;
width: 20px;
border-radius: 50%;
position: relative;
}
.eye1 {
bottom: 5px;
left: 15px;
}
.eye2 {
bottom: 25px;
left: 60px;
}
.eyeball {
background-color: white;
height: 8px;
width: 8px;
border-radius: 50%;
position: relative;
top: 5px;
left: 5px;
}
.ear1,
.ear2 {
background-color: #95755e;
height: 30px;
width: 60px;
border-radius: 0 0 30px 30px;
position: relative;
z-index: -1;
}
.ear1 {
bottom: 75px;
right: 23px;
transform: rotate(-25deg);
}
.ear2 {
bottom: 105px;
left: 60px;
transform: rotate(25deg);
}
.nose {
background-color: #ee0000;
height: 22px;
width: 35px;
border-radius: 50%;
position: relative;
bottom: 60px;
left: 30px;
}
.nose2 {
background-color: #f8453b;
height: 9px;
width: 15px;
border-radius: 50%;
position: relative;
bottom: 78px;
left: 43px;
}
.leg1,
.leg2 {
background-color: #6c584c;
height: 100px;
width: 20px;
position: relative;
border-radius: 0 0 8px 8px;
z-index: -2;
}
.leg1 {
left: 40px; /*reduced this */
top: 300px;
}
.leg2 {
left: 85px; /*reduced this */
top: 200px;
}
.body {
background-color: #95755e;
height: 200px;
width: 130px;
border-radius: 100px;
position: relative;
bottom: 60px;
left: 5px; /* reduced this */
z-index: -1;
}
<div class='pos'></div>
<div class="reindeer">
<div class="face">
<div class="antler1">
<div class="a1"></div>
<div class="a2"></div>
<div class="a3"></div>
</div>
<div class="antler2">
<div class="a1"></div>
<div class="a2"></div>
<div class="a3"></div>
</div>
<div class="eye1">
<div class="eyeball"></div>
</div>
<div class="eye2">
<div class="eyeball"></div>
</div>
<div class="ear1"></div>
<div class="ear2"></div>
<div class="nose"></div>
<div class="nose2"></div>
</div>
<div class="leg1"></div>
<div class="leg2"></div>
<div class="body"></div>
</div>
First of all, I want to let you know that this task should be built using HTML & CSS only.
Secondly, I have to put [from 'sun' div to 'neck'div] as a sibilings to the checkbox in order to control it by css, and now the problem that How to show my checkbox out of it's parent div which is the 'outerCircle'.
body {
width: 50%;
height: 100%;
margin: 20px;
}
article {
position: absolute;
background-color: transparent;
width: 400px;
height: 60%;
margin-top: 40px;
margin-left: 20px;
}
.day {
background-color: #F2D16D;
position: relative;
border-radius: 50%;
left: 70px;
width: 12%;
height: 10%;
top: -15px;
box-shadow: 1px 1px 3px 3px#F2D16D;
}
.moon {
position: relative;
top: -60px;
left: 90%;
height: 40px;
width: 50px;
box-shadow: -12px 2px 0 8px #E1E1E1;
border-radius: 50%;
filter: drop-shadow(9px 9px 6px #E1E1E1);
}
.outerCircle {
/* top: -50%; */
position: absolute;
/* z-index: 1; */
width: 100%;
height: 80%;
border-radius: 50%;
border: 15px solid #46A679;
overflow: hidden;
display: block;
}
.innerCircle {
position: absolute;
z-index: -2;
background-color: #E0E0E0;
width: 210%;
height: 795%;
border-radius: 50%;
top: 205%;
left: -65%;
/* overflow: hidden; */
}
.sun {
background-color: #F2D16D;
position: relative;
width: 30%;
height: 120%;
border-radius: 50%;
left: 70%;
top: 280%;
}
.catBody {
position: relative;
z-index: -1;
background-color: #E4774F;
height: 460%;
width: 120%;
top: 180px;
right: 40px;
transform: translate(0%, 10%);
}
.leftear,
.rightear {
position: relative;
width: 0%;
height: 0%;
}
.leftear {
border-top: 70px solid transparent;
border-right: 100px solid #E4774F;
left: 100px;
bottom: 194%;
}
.rightear {
border-top: 70px solid transparent;
border-left: 100px solid #E4774F;
left: -40px;
bottom: 334%;
}
.leftEye {
position: relative;
z-index: 1;
background-color: white;
width: 15%;
height: 60%;
border-radius: 50%;
bottom: 220%;
left: 10%;
}
.rightEye {
position: relative;
z-index: 1;
background-color: white;
width: 15%;
height: 60%;
border-radius: 50%;
bottom: 280%;
left: 55%;
}
.noise {
position: fixed;
background-color: #0D0D0D;
/* z-index: 1; */
width: 3%;
height: 2%;
border-radius: 50%;
top: 410px;
left: 245px;
}
.neck {
position: absolute;
/* z-index: -1; */
width: 0;
height: 0;
top: 390;
left: -40px;
border-left: 120px solid transparent;
border-right: 120px solid transparent;
border-top: 120px solid white;
}
/* switch section */
.button input {
/* Remember: this is to clean the shape of the radio button */
opacity: 0;
width: 0;
height: 0;
}
.button:hover {
cursor: pointer;
}
.button {
display: inline-block;
position: absolute;
z-index: 3;
width: 200px;
height: 50px;
left: 120px;
top: -115;
}
.slider {
position: absolute;
top: -10;
left: 0;
right: 0;
bottom: 0;
background-color: #47AB84;
border-radius: 190px;
transition: .7s;
}
/* internal circle */
.slider:before {
position: absolute;
content: "";
left: 4px;
bottom: 4px;
background-color: #FBE26C;
transition: all .7s;
}
.round:before {
top: 5px;
width: 20px;
height: 20px;
border-radius: 50%;
border: 15px solid #65E3B5;
}
/* Animate the switch */
input:checked+.slider::before {
transform: translateX(140px);
}
#select1:checked~.innerCircle {
background-color: #0D0D0D;
}
#select1:checked~.sun {
background-color: white;
left: 0%;
}
#select1:checked~.leftEye {
height: 10%;
position: relative;
z-index: 1;
background-color: white;
width: 15%;
/* height: 60%; */
border-radius: 50%;
bottom: 220%;
/* left: 10%; */
}
#select1:checked~.rightEye {
height: 10%;
position: relative;
z-index: 1;
background-color: white;
width: 15%;
/* height: 60%; */
border-radius: 50%;
bottom: 230%;
/* left: 55%; */
}
.catBody:hover {
position: relative;
z-index: -1;
background-color: #E4774F;
height: 460%;
width: 120%;
top: 200px;
/* right: 30px; */
transform: translate(0%, 10%);
}
.catBody:hover~.leftear {
border-top: 70px solid transparent;
border-right: 100px solid #E4774F;
/* left: 110px; */
bottom: 150%;
}
.catBody:hover~.rightear {
border-top: 70px solid transparent;
border-left: 100px solid #E4774F;
/* left: -30px; */
bottom: 280%;
}
.catBody:hover~.rightEye {
height: 10%;
position: relative;
z-index: 1;
background-color: white;
width: 15%;
/* height: 60%; */
border-radius: 50%;
bottom: 230%;
/* left: 60%; */
}
.catBody:hover~.leftEye {
height: 10%;
position: relative;
z-index: 1;
background-color: white;
width: 15%;
/* height: 60%; */
border-radius: 50%;
bottom: 220%;
/* left: 15%; */
}
#select1:checked~.catBody:hover~.rightEye {
width: 15%;
height: 60%;
bottom: 280%;
/* left: 55%; */
}
#select1:checked~.catBody:hover~.leftEye {
width: 15%;
height: 60%;
/* left: 10%; */
}
<article role="img">
<div class="day"></div>
<div class="moon"></div>
<div class="whole">
<div class="outerCircle">
<label class="button" for="select1">
<input id="select1" type="checkbox">
<span class="slider round"></span>
<div class="innerCircle"></div>
<div class="sun"></div>
<div class="catBody"></div>
<div class="leftear"></div>
<div class="rightear"></div>
<div class="leftEye"></div>
<div class="rightEye"></div>
<div class="noise"></div>
<div class="neck"></div>
</label>
</div>
</div>
</article>
I had to put the divs and the checkbox inside it
because the outer circle should above all and the over flow of the 'catBody' should be behind the 'outerCircle' as shown in the picture,
and I tried to use z-index but it didn't work with me, because it effected on hover work. How do I deal with it?
I have no idea what this is called but I want to build this nav the way it is on the picture I came pretty far using tailwind and custom css, but I'm stuck.
Does anyone know what this is called (to update the title) and how to build it?
My attempt:
.active::before {
content: "";
position: absolute;
background-color: transparent;
border-color: white;
border-width: 0 0.5rem 0.5rem 0;
width: 2rem;
height: 2rem;
right: -0.5rem;
border-radius: 0 0 100% 0;
top: -1.5rem;
}
.active::after {
content: "";
position: absolute;
background-color: transparent;
border-color: white;
border-width: 0.5rem 0.5rem 0 0;
width: 2rem;
height: 2rem;
right: -0.5rem;
border-radius: 0 100% 0 0;
bottom: -1.5rem;
}
.active-link {
display: flex;
justify-content: center;
align-items: center;
background-color: white;
border-top-left-radius: 10rem;
border-bottom-left-radius: 10rem;
width: 5rem;
height: 2rem;
}
<link href="https://unpkg.com/tailwindcss#^1.0/dist/tailwind.min.css" rel="stylesheet" />
<nav class="w-32 h-64 bg-indigo-900 rounded-xl">
<div class="flex flex-col items-center justify-between h-full py-12">
<div>
Title
</div>
<div class="w-full">
<ul class="flex flex-col items-center space-y-12 w-full">
<li class="w-full flex justify-center relative active">
<nuxt-link :to="menuItem.target" class="active-link">
<i class="text-black">Icon</i>
</nuxt-link>
</li>
</ul>
</div>
<div>
<i>Icon</i>
</div>
</div>
</nav>
This may be easier if all you need to do is add a classname to the selected element (as opposed to modifying the DOM structure whenever a new item in the navbar is clicked).
The following achieves this:
let nav = document.getElementsByClassName('navbar')[0];
for (let item of document.getElementsByClassName('item')) {
item.addEventListener('click', () => {
let selected = nav.querySelector('.item.selected');
if (selected) selected.classList.remove('selected');
item.classList.add('selected');
});
}
body { font-family: monospace; }
.navbar {
position: absolute;
left: 0; top: 0;
width: 60px; height: 100%;
padding-left: 10px;
background-color: rgba(70, 0, 170);
overflow: hidden;
}
.item {
position: relative;
height: 60px; line-height: 60px;
color: #fff;
text-align: center;
z-index: 1;
cursor: pointer;
}
.item.selected {
background-color: #fff;
border-radius: 100%;
color: #000;
}
.item.selected::before,
.item.selected::after {
content: ' '; display: block;
position: absolute;
left: 0; width: 100%; height: 100%;
pointer-events: none;
border-radius: 100%;
border: 50px solid rgba(0, 0, 0, 0);
border-right: 50px solid #fff;
margin-left: -50px;
z-index: -1;
}
.item.selected::before { bottom: 100%; margin-bottom: -50px; transform: rotate(45deg); }
.item.selected::after { top: 100%; margin-top: -50px; transform: rotate(-45deg); }
<div class="navbar">
<div class="item">(1)</div>
<div class="item">(2)</div>
<div class="item selected">(3)</div>
<div class="item">(4)</div>
</div>
That snippet is interactive, so try clicking menu items!
Note that the rounding is also very similar to the image you displayed, since we are using true circle radii.
The trick here is to add ::before and ::after elements to the selected item, and apply borders to them, remove all of the border except for one side, and finally rotate these pseudoelements so that the border goes where we want it. The following snippet demonstrates:
#keyframes styleBefore {
0% {
border: 0 solid #000;
margin-left: 0;
margin-bottom: 0;
}
20% {
border: 50px solid #000;
border-right: 50px solid #000;
margin-left: -50px;
margin-bottom: -50px;
}
40% {
border: 50px solid #000;
border-right: 50px solid #fff;
}
60% {
border: 50px solid transparent;
border-right: 50px solid #fff;
transform: rotate(0deg);
}
95% {
border: 50px solid transparent;
border-right: 50px solid #fff;
transform: rotate(45deg);
}
100% {
border: 50px solid transparent;
border-right: 50px solid transparent;
margin-left: -50px;
margin-bottom: -50px;
transform: rotate(45deg);
}
}
#keyframes styleAfter {
0% {
border: 0 solid #000;
margin-left: 0;
margin-top: 0;
}
20% {
border: 50px solid #000;
border-right: 50px solid #000;
margin-left: -50px;
margin-top: -50px;
}
40% {
border: 50px solid #000;
border-right: 50px solid #fff;
}
60% {
border: 50px solid transparent;
border-right: 50px solid #fff;
transform: rotate(0deg);
}
95% {
border: 50px solid transparent;
border-right: 50px solid #fff;
transform: rotate(-45deg);
}
100% {
border: 50px solid transparent;
border-right: 50px solid transparent;
margin-left: -50px;
margin-top: -50px;
transform: rotate(-45deg);
}
}
body { font-family: monospace; }
.navbar {
position: absolute;
left: 0; top: 0;
width: 90px; height: 100%;
padding-left: 10px;
background-color: rgba(70, 0, 170);
overflow: hidden;
}
.item {
position: relative; top: -85px;
height: 90px; line-height: 90px;
color: #fff;
text-align: center;
z-index: 1;
cursor: pointer;
font-size: 200%;
}
.item.selected {
background-color: #fff;
border-radius: 100%;
color: #000;
}
.item.selected::before,
.item.selected::after {
content: ' '; display: block;
position: absolute;
left: 0; width: 100%; height: 100%;
pointer-events: none;
border-radius: 100%;
z-index: -1;
}
.item.selected::before { bottom: 100%; animation: 10s infinite linear styleBefore; }
.item.selected::after { top: 100%; animation: 10s infinite linear styleAfter; }
<div class="navbar">
<div class="item">(1)</div>
<div class="item">(2)</div>
<div class="item selected">(3)</div>
<div class="item">(4)</div>
</div>
It's really a matter of pixels; to adjust pixel-wise the border-radius and top & bottom properties. Fiddled it.
.active::before {
content: "";
position: absolute;
background-color: transparent;
border-color: white;
border-width: 0 0.5rem 0.7rem 0;
width: 2rem;
height: 2rem;
right: -0.5rem;
border-radius: 0 0 100% 0;
top: -1.34rem;
outline: white;
}
.active::after {
content: "";
position: absolute;
background-color: #f8f8f800;
border-color: white;
border-width: 0.7rem 0.7rem 0px 0px;
width: 2rem;
height: 2rem;
right: -0.7rem;
border-radius: 0 100% 0 0;
bottom: -1.30rem;
}
.active-link {
display: flex;
float: right;
justify-content: center;
align-items: center;
background-color: white;
border-top-left-radius: 10rem;
border-bottom-left-radius: 10rem;
width: 8rem;
height: 5rem;
margin-left: 10px;
}
.active-link .text-black {
margin-left: -10px;
}
<link href="https://unpkg.com/tailwindcss#^1.0/dist/tailwind.min.css" rel="stylesheet" />
<nav class="w-24 h-64 bg-indigo-900 rounded-xl">
<div class="flex flex-col items-center justify-between h-full py-12">
<div>
Title
</div>
<div class="w-full">
<ul class="flex flex-col items-center space-y-12 w-full">
<li class="w-full flex justify-center relative active">
<nuxt-link :to="menuItem.target" class="active-link">
<i class="text-black">Icon</i>
</nuxt-link>
</li>
</ul>
</div>
<div>
<i>Icon</i>
</div>
</div>
</nav>
I was trying to participate in a CSS challenge when this occurred. Everything seems working as expected, however when clicking on the plus circle to display div#card the div.container loses it's top margin and I cannot understand why. Please if anyone can help me with this, I'd be really grateful - And maybe we can all learn from it ;)
Thanks!
Codepen: https://codepen.io/albertrf147/pen/LMKKeK
HTML
html,
body {
width: 100%;
height: 100%;
}
body {
margin: 0px;
overflow: hidden;
background: lightblue;
}
.container {
width: 400px;
height: 400px;
margin: 20px auto !important;
position: relative;
display: flex;
flex-wrap: wrap;
background: white;
padding: 2px;
}
.square {
box-sizing: border-box;
padding: 2px;
width: 50%;
height: 50%;
position: relative;
background: white;
}
.square>img {
height: 100%;
width: 100%;
object-fit: cover;
display: block;
margin: auto;
}
.onhover {
box-sizing: border-box;
width: 100%;
height: 100%;
position: absolute;
cursor: pointer;
transition: all .6s ease-in-out;
}
.onhover:hover {
background: rgba(0, 0, 0, 0.5);
}
.circle-aux {
position: relative;
width: 100%;
height: 100%;
transition: all .6s ease-in-out;
}
.circle-aux:hover .circle {
visibility: visible;
opacity: 1;
transform: scale(0.2);
transition: all .6s ease-in-out;
}
.circle {
visibility: hidden;
opacity: 0;
position: absolute;
border-radius: 50%;
width: 100%;
height: 100%;
background: salmon;
}
.circle:before {
content: "";
background: white;
height: 50%;
width: 6px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.circle:after {
content: "";
background: white;
height: 6px;
width: 50%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.container-card {
visibility: hidden;
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
}
.container-card>img {
width: 100%;
height: 60%;
object-fit: cover;
}
.container-card:target {
visibility: visible;
}
.avatar {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border-radius: 50%;
box-shadow: 0px 0px 20px black;
width: 25%;
height: 25%;
background: white;
z-index: 2;
text-align: center;
font-family: calibri;
font-weight: bold;
color: white;
font-size: 18px;
}
.avatar>img {
box-sizing: border-box;
width: 100%;
height: 100%;
object-fit: cover;
border-radius: inherit;
padding: 4px;
}
.mini-circle {
display: inline-block;
width: 15%;
height: 15%;
border: 1px solid white;
border-radius: 50%;
margin-top: 12px;
}
.mini-circle:hover {
background: white;
cursor: pointer;
}
footer {
box-sizing: border-box;
position: absolute;
bottom: 0;
left: 0;
background: salmon;
height: 50%;
width: 100%;
z-index: 1;
padding: 2px;
}
.close {
position: absolute;
border-radius: 50%;
width: 8%;
height: 8%;
background: black;
transform: rotate(45deg);
right: 10px;
top: 10px;
cursor: pointer;
}
.close:before {
content: "";
background: white;
height: 60%;
width: 2px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.close:after {
content: "";
background: white;
height: 2px;
width: 60%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<main>
<div class="container">
<div class="square">
<div class="onhover">
<div class="circle-aux">
<a class="circle" href="#card"></a>
</div>
</div>
<img src="https://images.pexels.com/photos/305241/pexels-photo-305241.jpeg?auto=compress&cs=tinysrgb&h=650&w=940" />
</div>
<div class="square">
<div class="onhover">
<div class="circle-aux">
<div class="circle"></div>
</div>
</div>
<img src="https://images.pexels.com/photos/1546711/pexels-photo-1546711.jpeg?auto=compress&cs=tinysrgb&h=650&w=940" />
</div>
<div class="square">
<div class="onhover">
<div class="circle-aux">
<div class="circle"></div>
</div>
</div>
<img src="https://images.pexels.com/photos/1800433/pexels-photo-1800433.jpeg?auto=compress&cs=tinysrgb&h=650&w=940" />
</div>
<div class="square">
<div class="onhover">
<div class="circle-aux">
<div class="circle"></div>
</div>
</div>
<img src="https://images.pexels.com/photos/1757111/pexels-photo-1757111.jpeg?auto=compress&cs=tinysrgb&h=650&w=940" />
</div>
<div id="card" class="container-card">
<a class="close" href="#"></a>
<img src="https://images.pexels.com/photos/1769331/pexels-photo-1769331.jpeg?auto=compress&cs=tinysrgb&h=650&w=940" />
<div class="avatar">
<img src="https://images.pexels.com/photos/769772/pexels-photo-769772.jpeg?auto=compress&cs=tinysrgb&h=650&w=940" />
<span>David Craig</span>
<span>
<div class="mini-circle"></div>
<div class="mini-circle"></div>
<div class="mini-circle"></div>
</span>
</div>
<footer></footer>
</div>
</div>
</main>
Welcome to SO!
As the appearing container is position: absolute no margin takes effect.
You need to work with the top attribute to place it properly.
Check this out: https://codepen.io/anon/pen/pGzVyL
For more informations click here: https://www.w3schools.com/css/css_positioning.asp
i am creating a template for a website. there i want to create a menu like this
I found the below code as a solution
but I can't get the div to divided into 4 parts and add the text in a responsive way. Can do it using position:absolute, but the it is not responsive. How can I achieve this using css in a responsive way?
.background {
background-color: #BCBCBC;
width: 100px;
height: 50px;
padding: 0;
margin: 0
}
.line1 {
width: 112px;
height: 47px;
border-bottom: 1px solid red;
-webkit-transform: translateY(-20px) translateX(5px) rotate(27deg);
position: absolute;
/* top: -20px; */
}
.line2 {
width: 112px;
height: 47px;
border-bottom: 1px solid green;
-webkit-transform: translateY(20px) translateX(5px) rotate(-26deg);
position: absolute;
top: -33px;
left: -13px;
}
<div class="background">
<div class="line1"></div>
<div class="line2"></div>
</div>
You can use CSS Flexbox & CSS Transform properties to achieve this. Have a look at the snippet below:
body {
padding: 20px;
}
.menu-cover {
width: 360px;
height: 360px;
overflow: hidden;
background: #eee;
}
.menu {
list-style: none;
margin: -70px 0 0 -70px;
padding: 80px;
display: flex;
flex-wrap: wrap;
width: calc(600px - 100px);
height: calc(600px - 100px);
position: relative;
transform: rotate(45deg);
transform-origin: center;
}
.menu:before {
content: '';
position: absolute;
top: 0;
left: 50%;
transform: translateX(-50%);
width: 1px;
height: 100%;
background-color: #aaa;
}
.menu:after {
content: '';
position: absolute;
top: 50%;
left: 0;
transform: translateY(-50%);
width: 100%;
height: 1px;
background-color: #aaa;
}
.item {
width: 50%;
}
.item a {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
transform: rotate(-45deg);
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/>
<div class="menu-cover">
<ul class="menu">
<li class="item">
Bussiness
</li>
<li class="item">
Team
</li>
<li class="item">
Talent
</li>
<li class="item">
Group
</li>
</ul>
</div>
Hope this helps!
You can use pseudo elements like before and after. Kindly review the updated answer. Hope it is helpful to you.
.background {
background-color: #BCBCBC;
width: 100px;
height: 100px;
padding: 0;
margin: 0;
position: relative;
overflow: hidden;
}
.background:before {
width: 1px;
height: 500px;
background :red;
-webkit-transform: rotate(45deg);
position: absolute;
content:'';
left: 0;
right: 0;
margin:-200px auto 0;
}
.background:after {
width: 1px;
height: 500px;
background :green;
-webkit-transform: rotate(-45deg);
position: absolute;
content:'';
left: 0;
right: 0;
margin:-200px auto 0;
}
<div class="background">
</div>
Please check the below code. You can implement your requirement in the same way. I have added <span> tags to show the text.
.background {
background-color: #BCBCBC;
width: 100px;
height: 50px;
padding: 0;
margin: 0
}
.line1 {
width: 112px;
height: 47px;
border-bottom: 1px solid red;
-webkit-transform: translateY(-20px) translateX(5px) rotate(27deg);
position: absolute;
/* top: -20px; */
}
.line2 {
width: 112px;
height: 47px;
border-bottom: 1px solid green;
-webkit-transform: translateY(20px) translateX(5px) rotate(-26deg);
position: absolute;
top: -33px;
left: -13px;
}
<div class="background">
<span style="float:left;padding-left:20%">Business
</span>
<span style="float:left;padding-left:5%">Team
</span>
<span style="float:right;padding-left:5%">Talent
</span>
<span style="float:left;padding-left:20%">Group
</span>
<div class="line1"></div>
<div class="line2"></div>
</div>
https://jsfiddle.net/t3z8q2k4/