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
Community Proposals
Community Proposals
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 See all your notifications »
Q&A

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.

Post History

77%
+5 −0
Q&A Child div doesn't inherit parent's div background-color

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 o...

1 answer  ·  posted 2y ago by Bennshinpoes‭  ·  last activity 2y ago by r~~‭

Question html css
#1: Initial revision by user avatar Bennshinpoes‭ · 2022-09-25T15:22:41Z (about 2 years ago)
Child div doesn't inherit parent's div background-color
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>