Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Comments on Child div doesn't inherit parent's div background-color
Post
Child div doesn't inherit parent's div background-color
+5
−0
I have a parent div with two child divs. I want the parent div and the child divs to have a blue background color when it's hovered. But the child divs doesn't inherit the background color. It is only applied to the parent's div only. Does this have to be applied separatly per div? I have tried to use the <div style="clear:both;"></div>
method, but that doesn't work for me.
CSS:
.h1{
color: rgb(0, 238, 255);
display: flex;
justify-content: center;
padding-top: 25px;
}
*{
margin: 0;
padding: 0;
background: rgb(3, 28, 87);
}
.mainHeader {
width: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
align-content: center;
align-self: center;
}
.outsideClock{
display: flex;
justify-content: center;
align-items: center;
vertical-align: middle;
height: 100%;
padding: 30vh;
}
#clock{
height: 20vh;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
margin: 0px auto;
left: 0;
right: 0;
}
.datetime{
color: #ffffff;
background-color: rgb(3, 28, 87);
font-family: "Segoe UI", sans-serif;
width: 338px;
padding: 15px 10px;
border: 5px solid hsl(207, 80%, 52%);
border-radius: 5px;
-webkit-box-reflect: below 1px linear-gradient(transparent, rgba(255,255,255,0.1));
}
.datetime:hover {
background: hsl(207, 80%, 52%);
box-shadow: 0 0 30px;
}
.date{
font-size: 20px;
font-weight: 600;
text-align: center;
letter-spacing: 2px;
}
.time{
font-size: 60px;
display: flex;
justify-content: center;
align-items: center;
}
.time span:not(:last-child) {
position: relative;
margin: 0 6px;
font-weight: 600;
text-align: center;
letter-spacing: 2px;
}
.time span:last-child {
background: hsl(207, 80%, 52%);
font-size: 30px;
font-weight: 600;
text-transform: uppercase;
margin-top: 10px;
padding: 0 3px;
border-radius: 3px;
}
HTML:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>The Digital Clock</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="mainHeader">
<h1 class="h1">Current Time</h1>
<!-- digital clock -->
<div class="outsideClock">
<div id="clock" class="datetime">
<div class="date">
<span id="dayname">Day</span>
<span id="daynum">Num</span>
<span id="month">Month</span>
<span id="year">Year</span>
</div>
<div class="time">
<span id="hour">00</span>:
<span id="minutes">00</span>:
<span id="seconds">00</span>
<span id="period">am</span>
</div>
</div>
</div>
</div>
</body>
</html>
1 comment thread