0

I want to make the background-color for a DIV not body light gray and another div inside it dark gray. I tried the following:

    - Setting the first div width and height to 100%
    - Setting the first div min-width and min-height to 100%
    - Setting the first div max-width and max-height to 100%
    - Setting html and the first div width and height to 100

.div1 {
    min-height: 100%;
    min-width: 100%;
    background-color: lightblue;
}

.div2 {

    background: black;
}
<html>
<body>
<div class="div1">
    <div class="div2">
    </div>
</div>
</body>
</html>
  • Which div do you want to be 100%? And have you tried adding `position: absolute;` to `.div1`? – John May 13 '20 at 01:05

1 Answers1

0

You need to set the html and body dimensions.

html,body {
  height: 100%;
  width: 100%;
}

updated code:

html,body {
  height: 100%;
  width: 100%;
}

.div1 {
    min-height: 100%;
    min-width: 100%;
    background-color: lightblue;
}

.div2 {

    background: black;
}
<html>
<body>
<div class="div1">
    <div class="div2">
    </div>
</div>
</body>
</html>
Julian Paolo Dayag
  • 3,562
  • 3
  • 20
  • 32