Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read
Q&A

Child div doesn't inherit parent's div background-color

+4
−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>
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

clear (1 comment)

1 answer

+8
−0

It's because of this rule:

*{
  background: rgb(3, 28, 87);
}

That applies the darker blue background to every element individually, and that isn't overridden when you change the background of a parent element.

Consider applying your default background color to the body element only.

Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

Works for me (1 comment)

Sign up to answer this question »