Skip to content

C070 CSS Animation

In this task, you will create a simple transition so that a div changes when you hover over it with the mouse.

You can use the following HTML/CSS as a starting point:

<!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>
    <style>
      #d1 {
        width: 50px;
        height: 50px;
        background-color: aqua;
      }
    </style>
  </head>
  <body>
    <div id="d1">Demo</div>
  </body>
</html>

This will create a “blue” box of size 50x50.

Your task is to ensure that div#d1 changes its size (e.g., to 100px) and color (e.g., red) over 2 seconds when hovered over.

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>
    <style>
    #d1 {
        width: 50px;
        height: 50px;
        background-color: aqua;
        transition: 2s;
    }

    #d1:hover {
        background-color: coral;
        width: 100px;
        height: 100px;
    }
    </style>
</head>
<body>
    <div id="d1">Demo</div>
</body>
</html>