Rounded Semicircle with CSS - html

I'm struggling to make the semicircle edges round, where can i fix my code?
.circle {
position: absolute;
width: 80px;
height: 50px;
background-color: transparent;
top: 70;
left: 20;
border-bottom-right-radius: 70px;
border-bottom-left-radius: 70px;
border: 20px solid #fff58f;
border-top: 0;
}
<div class="circle"></div>

Only possible way to do this in pure CSS is by faking it with pseudo-elements:
.wrapper {
background: darkorange;
border-radius: 50%;
width: 200px;
height: 200px;
display: grid;
justify-content: center;
align-content: center;
}
.box {
background: orange;
width: 120px;
height: 120px;
border-radius: 50%;
position: relative;
}
.circle {
position: absolute;
width: 100px;
height: 50px;
background-color: transparent;
bottom: 0;
left: -10px;
border-bottom-right-radius: 70px;
border-bottom-left-radius: 70px;
border: 20px solid #FFF58F;
border-top: 0
}
.circle::before, .circle::after {
content: '';
width: 20px;
height: 20px;
border-radius: 50%;
position: absolute;
background: #FFF58F;
}
.circle::before {
left: -20px;
top: -8px;
}
.circle::after {
right: -20px;
top: -8px;
}
<div class="wrapper">
<div class="box">
<div class="circle"></div>
</div>
</div>

Another possibility with css
I have used ::before and ::after pseudo elements for the rounded corner for the semi circle.
.parentcircle {
position: absolute;
background: #824b20;
width: 160px;
height: 160px;
border-radius: 50%;
padding: 30px;
}
.outercircle {
position: relative;
width: 100%;
height: 100%;
background: #e08027;
border-radius: 50%;
}
.circle {
position: relative;
width: calc(100% - 20px);
height: calc(50% - 10px);
background-color: transparent;
top: 50%;
left: -10px;
border-bottom-right-radius: 50% 100%;
border-bottom-left-radius: 50% 100%;
border: 20px solid #FFF58F;
border-top: 0
}
.circle::before {
content: '';
width: 20px;
height: 20px;
border-radius: 50%;
position: absolute;
background: #FFF58F;
top: -10px;
left: -20px;
}
.circle::after {
content: '';
width: 20px;
height: 20px;
border-radius: 50%;
position: absolute;
background: #FFF58F;
top: -10px;
left: 100%;
}
<div class="parentcircle">
<div class="outercircle">
<div class="circle"></div>
</div>
</div>

Related

How to make Reindeer centered

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>

How to show my checkbox out of it's parent 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?

Pure CSS Bulb - Two shapes change color on click

I made a bulb in pure CSS and I want the bulb to change color on click. But my bulb shape consists of two shapes, so I cannot hover over both. Is there a way to solve this without using JavaScript, sticking to CSS only? Is there maybe a way to create this yellow shape without the need to combine two? Or any other way I could have the hover effect working.
.box {
position: relative;
margin: auto;
display: block;
margin-top: 8%;
width: 600px;
height: 600px;
background: white;
}
#circle {
position: absolute;
width: 40%;
height: 40%;
background: yellow;
top: 20%;
left: 30%;
margin: 0 auto;
border-radius: 50%;
}
#trapezoid {
position: absolute;
background: yellow;
height: 30%;
width: 40%;
left: 30%;
top: 42%;
-webkit-clip-path: polygon(0 0, 100% 0, 80% 100%, 20% 100%);
}
#bottom1 {
position: absolute;
height: 5%;
width: 25%;
background: grey;
top: 72%;
left: 37.5%;
z-index: 1;
}
#bottom1:before {
content: "";
height: 100%;
width: 20%;
background: grey;
display: block;
position: absolute;
border-radius: 50%;
left: -8%;
}
#bottom1:after {
content: "";
height: 100%;
width: 20%;
background: grey;
display: block;
position: absolute;
border-radius: 50%;
right: -8%;
}
#bottom2 {
position: absolute;
height: 5%;
width: 22%;
background: grey;
top: 78%;
left: 39%;
}
#bottom2:before {
content: "";
height: 100%;
width: 20%;
background: grey;
display: block;
position: absolute;
border-radius: 50%;
left: -8%;
}
#bottom2:after {
content: "";
height: 100%;
width: 20%;
background: grey;
display: block;
position: absolute;
border-radius: 50%;
right: -8%;
}
#bottom3 {
position: absolute;
height: 5%;
width: 18%;
background: grey;
top: 84%;
left: 41%;
z-index: 1;
}
#bottom3:before {
content: "";
height: 100%;
width: 20%;
background: grey;
display: block;
position: absolute;
border-radius: 50%;
left: -8%;
}
#bottom3:after {
content: "";
height: 100%;
width: 20%;
background: grey;
display: block;
position: absolute;
border-radius: 50%;
right: -8%;
}
#shine {
width: 20%;
height: 20%;
background: white;
border-radius: 50%;
top: 20%;
position: absolute;
left: 18%;
}
.halfCircle {
height: 100px;
width: 100px;
border-radius: 0 0 90px 90px;
}
#halfCircle {
height: 45px;
width: 90px;
border-radius: 0 0 90px 90px;
background: black;
margin: 0 auto;
top: 88%;
position: relative;
}
.drop {
width: 5%;
height: 5%;
position: absolute;
border: 15px solid orange;
}
#left {
left: 38%;
top: 45%;
border-radius: 50% 50% 0 50%;
}
#left:after {
content: "";
height: 110px;
width: 24px;
border: 15px solid orange;
display: block;
position: absolute;
left: 100%;
top: 100%;
}
#right {
right: 38%;
top: 45%;
border-radius: 50% 50% 50% 0;
}
#circle:hover {
background: red;
}
#trapezoid:hover {
background: red;
}
<div class='box'>
<div id='circle'>
<div id='shine'></div>
</div>
<div id='trapezoid'></div>
<div id='bottom1'></div>
<div id='bottom2'></div>
<div id='bottom3'></div>
<div id='halfCircle'></div>
<div class='drop' id='left'></div>
<div class='drop' id='right'></div>
<div id='wire'></div>
</div>
You don't have to apply the :hover directly to the element that you want to change. You can hoist it to a wrapping element and apply it there.
Considering your example, your selectors would likely be something along the lines of:
.box:hover #circle {
background: red;
}
.box:hover #trapezoid {
background: red;
}
Consider this concrete example. Hovering either of the nested <div> cause the sibling <div> to also change color because #container is being :hovered.
#foo,
#bar {
height: 20px;
background-color: green;
border: 1px solid white;
}
#foo:hover,
#bar:hover {
background-color: blue;
border: 1px dashed yellow;
}
#container:hover #foo,
#container:hover #bar {
background-color: red;
}
<div id="container">
<div id="foo">foo</div>
<div id="bar">bar</div>
</div>

relative position of div inside div

I'm designing a logo in CSS3.
I have made a class .logo with particular height and width. Rest of the div inside .logo class will resize its position relative to parent div.
This is my CSS code.
.logo {
width: 200px;
height: 200px;
position: fixed;
}
.logo .vertical-left {
width: 25px;
height: 60%;
position: absolute;
bottom: 0;
background-color: #09aaba;
}
.logo .vertical-right {
width: 25px;
height: 65%;
background-color: #09aaba;
margin-left: 60%;
top: 0;
position: absolute;
}
.logo .vertical-right2 {
width: 25px;
height: 60%;
background-color: #ba1dd4;
margin-left: 60%;
top: 0;
position: absolute;
}
.logo .horizontal-top {
width: 100%;
height: 25px;
background-color: #09aaba;
position: absolute;
top: 30%;
border-radius: 10px 0;
}
.logo .horizontal-top2 {
width: 60%;
height: 25px;
background-color: #ba1dd4;
position: absolute;
top: 30%;
right: 0;
}
.logo .horizontal-bottom {
width: 72.5%;
height: 25px;
background-color: #09aaba;
position: absolute;
top: 65%;
border-radius: 10px 0;
}
/* triangle */
.logo .arrow-left {
width: 0;
height: 0;
border-top: 12px solid transparent;
border-bottom: 12px solid transparent;
position: absolute;
top: 30%;
left: 35%;
border-right:10px solid #ba1dd4;
}
.logo .arrow-down {
width: 0;
height: 0;
border-left: 12px solid transparent;
border-right: 13px solid transparent;
position: absolute;
top: 60%;
right: 27%;
border-top: 10px solid #ba1dd4;
}
<div class="logo">
<div class="vertical-left"></div>
<div class="vertical-right"></div>
<div class="vertical-right2"></div>
<div class="horizontal-top"></div>
<div class="horizontal-top2"></div>
<div class="horizontal-bottom"></div>
<div class="arrow-left"></div>
<div class="arrow-down"></div>
</div>
Here .logo div size is 200px X 200px. When I change it to 300px X 300px the inside div are messed up as in following snippet.
.logo {
width: 300px;
height: 300px;
position: fixed;
}
.logo .vertical-left {
width: 25px;
height: 60%;
position: absolute;
bottom: 0;
background-color: #09aaba;
}
.logo .vertical-right {
width: 25px;
height: 65%;
background-color: #09aaba;
margin-left: 60%;
top: 0;
position: absolute;
}
.logo .vertical-right2 {
width: 25px;
height: 60%;
background-color: #ba1dd4;
margin-left: 60%;
top: 0;
position: absolute;
}
.logo .horizontal-top {
width: 100%;
height: 25px;
background-color: #09aaba;
position: absolute;
top: 30%;
border-radius: 10px 0;
}
.logo .horizontal-top2 {
width: 60%;
height: 25px;
background-color: #ba1dd4;
position: absolute;
top: 30%;
right: 0;
}
.logo .horizontal-bottom {
width: 72.5%;
height: 25px;
background-color: #09aaba;
position: absolute;
top: 65%;
border-radius: 10px 0;
}
/* triangle */
.logo .arrow-left {
width: 0;
height: 0;
border-top: 12px solid transparent;
border-bottom: 12px solid transparent;
position: absolute;
top: 30%;
left: 35%;
border-right: 10px solid #ba1dd4;
}
.logo .arrow-down {
width: 0;
height: 0;
border-left: 12px solid transparent;
border-right: 13px solid transparent;
position: absolute;
top: 60%;
right: 27%;
border-top: 10px solid #ba1dd4;
}
<div class="logo">
<div class="vertical-left"></div>
<div class="vertical-right"></div>
<div class="vertical-right2"></div>
<div class="horizontal-top"></div>
<div class="horizontal-top2"></div>
<div class="horizontal-bottom"></div>
<div class="arrow-left"></div>
<div class="arrow-down"></div>
</div>
How can I have a responsive logo which will adjust according to parent height and width?
Setting the dimensions to percentages should make it resize. But the pointed arrow tips won't because they can't be set to percentage. The code below makes the logo resize but you will see that the arrow head cuts off at some point. Hope this puts you in the right direction
.logo {
width: 300px;
height: 300px;
position: fixed;
}
.logo:nth-child(2) {
width: 100px;
height: 100px;
position: absolute;
right: 0;
}
.logo .vertical-left {
width: 12.5%;
height: 60%;
position: absolute;
bottom: 0;
background-color: #09aaba;
}
.logo .vertical-right {
width: 12.5%;
height: 65%;
background-color: #09aaba;
margin-left: 60%;
top: 0;
position: absolute;
}
.logo .vertical-right2 {
width: 12.5%;
height: 60%;
background-color: #ba1dd4;
margin-left: 60%;
top: 0;
position: absolute;
display: flex;
justify-content: center ;
align-items: flex-end;
}
.logo .horizontal-top {
width: 100%;
height: 12.5%;
background-color: #09aaba;
position: absolute;
top: 30%;
border-radius: 10px 0;
}
.logo .horizontal-top2 {
width: 60%;
height: 12.5%;
background-color: #ba1dd4;
position: absolute;
top: 30%;
right: 0;
display: flex;
justify-content: center;
flex-direction: column;
}
.logo .horizontal-bottom {
width: 72.5%;
height: 12.5%;
background-color: #09aaba;
position: absolute;
top: 65%;
border-radius: 10px 0;
}
/* triangle */
.logo .arrow-left {
}
.logo .arrow-down {
}
.vertical-right2:after {
content: '';
width: 100%;
height: 0;
border-left: 12px solid transparent;
border-right: 13px solid transparent;
position: relative;
bottom: -10px;
border-top: 10px solid #ba1dd4;
z-index: 100;
}
.horizontal-top2:before {
content: '';
width: 0;
border-top: 12px solid transparent;
border-bottom: 12px solid transparent;
position: relative;
border-right: 10px solid #ba1dd4;
left: -10px;
flex-grow: 1;
z-index: 100;
}
<div class="logo">
<div class="vertical-left"></div>
<div class="vertical-right"></div>
<div class="vertical-right2"></div>
<div class="horizontal-top"></div>
<div class="horizontal-top2"></div>
<div class="horizontal-bottom"></div>
<div class="arrow-left"></div>
<div class="arrow-down"></div>
</div>
<div class="logo">
<div class="vertical-left"></div>
<div class="vertical-right"></div>
<div class="vertical-right2"></div>
<div class="horizontal-top"></div>
<div class="horizontal-top2"></div>
<div class="horizontal-bottom"></div>
<div class="arrow-left"></div>
<div class="arrow-down"></div>
</div>
I've tweaked your CSS a bit:
.logo .vertical-right {
width: 25px;
height: calc(65% - 25px);
background-color: #09aaba;
margin-left: 60%;
bottom: calc(27% + 25px);
position: absolute;
}
.logo .vertical-right2 {
width: 25px;
height: 60%;
background-color: #ba1dd4;
margin-left: 60%;
bottom: 40%;
position: absolute;
}
.logo .horizontal-top {
width: 100%;
height: 25px;
background-color: #09aaba;
position: absolute;
bottom: 60%;
border-radius: 10px 0;
}
.logo .horizontal-top2 {
width: 60%;
height: 25px;
background-color: #ba1dd4;
position: absolute;
bottom: 60%;
right: 0;
}
.logo .horizontal-bottom {
width: calc(60% + 25px);
height: 25px;
background-color: #09aaba;
position: absolute;
bottom: 27%;
border-radius: 10px 0;
}
/* triangle */
.logo .arrow-left {
width: 0;
height: 0;
border-top: 12px solid transparent;
border-bottom: 12px solid transparent;
position: absolute;
bottom: 60%;
right: 60%;
border-right: 10px solid #ba1dd4;
}
.logo .arrow-down {
width: 0;
height: 0;
border-left: 12px solid transparent;
border-right: 13px solid transparent;
position: absolute;
top: 60%;
margin-left: 60%;
border-top: 10px solid #ba1dd4;
}
First off I agree with other posters here that an image sounds more like what should be getting used in this case. However that doesn't really answer the question; it's just handy advice.
With the sort of positioning you're attempting try to make your elements use a common "point of origin" within your container. In other words always try to align them from the same edges. You had a bit of a mixture before of top, right, left, and bottom. I've made elements that respect each other use the same edge for calculating distance. I've also added a couple of CSS calc functions like this one height: calc(65% - 25px);, since you're mixing mostly percentage elements with a couple of static pixel based measurements.
A perfect way to achieve what you want to do is to go for a SVG logo.
SVGs can be resized without breaking, and are quite powerful.
This tutorial could help you get started.

How to create the corner that show in picture with css in webpage?

How to create the curve that you see in picture with CSS and HTML?
Can I use CSS border radius or use other solution?
You could do it with two divs and psuedo elements :before and :after. Working code below
.top-bar{
height: 100px;
width: 100%;
background-color: #55c3ff;
}
.curved-bottom{
width: 80%;
margin: 0 auto;
height: 50px;
background-color: #55c3ff;
border-radius: 0 0 20px 20px;
position: relative;
}
.curved-bottom:before {
height: 50px;
width: 16%;
background-color: white;
border-top-right-radius: 10px;
left: -16%;
content: '';
position: absolute;
top: -8px;
}
.curved-bottom:after {
height: 50px;
width: 16%;
background-color: white;
border-top-left-radius: 10px;
right: -16%;
content: '';
position: absolute;
top: -8px;
}
<div class="top-bar"></div>
<div class="curved-bottom"></div>
If your main horizontal blue bar is a div, and the box sticking down is a separate div, you can use the pseudo elements :before and :after to create those inner radius.
See the following as an example:
html,
body {
padding: 0;
margin: 0;
}
.header {
position: relative;
background-color: #5DC4FD;
width: 100%;
height: 160px;
}
.tab {
position: relative;
top: 130px;
background-color: #5DC4FD;
width: 80%;
height: 100px;
margin: 0 auto;
border-radius: 0 0 30px 30px;
}
.tab:before {
position: absolute;
content: "";
left: -50%;
width: 50%;
height: 100px;
background-color: white;
border-radius: 0 30px 0 0;
}
.tab:after {
position: absolute;
content: "";
right: -50%;
width: 50%;
height: 100px;
background-color: white;
border-radius: 30px 0 0 0;
}
<div class="header">
<div class="tab">
</div>
</div>
Well, you could use overlapping divs like this:
#top {
background: #00BFFF;
width: 100%;
height: 150px;
}
#container{
display: flex;
}
#mid{
background: #00BFFF;
width: 70%;
height: 50px;
border-bottom-left-radius: 25px;
border-bottom-right-radius: 25px;
}
#left{
background: #FFFFFF;
margin-top: -50px;
width: 15%;
height: 50px;
border-top-right-radius: 25px;
}
#right{
background: #FFFFFF;
margin-top: -50px;
width: 15%;
height: 50px;
border-top-left-radius: 25px;
}
<div id="top"></div>
<div id="container">
<div id="left"></div>
<div id="mid"></div>
<div id="right"></div>
</div>
but I'd recommend using a background image with the desired shape