Skip to content

C040 Box Model

Create a new index.html with the following content:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
  </body>
</html>

Now add a style.css file and ensure the following:

  • All divs should have a height and width of 100px.
  • All divs should have a margin of 20px.
  • All divs should have a padding of 20px.
  • All divs should have a border of 1px solid black.
  • All divs should have a yellow background color:
  • Except for the second div, which should have a pink background color.
  • The third div should not be visible:
  • Experiment with both visibility: hidden and display: none to see the difference.

It should look something like this:

See a possible solution
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <link rel="stylesheet" href="style.css" />
    <title>Document</title>
</head>
<body>
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
</body>
</html>
div {
    width: 100px;
    height: 100px;
    background: yellow;
    margin: 20px;
    padding: 20px;
    border: 1px solid black;
}

div:nth-child(2) {
    background-color: pink;
}

div:nth-child(3) {
    visibility: hidden;
}