I am relatively new to html/css and have encountered a slight issue while trying to add transitions to a div element. When I hover over the div element, I would like it to smoothly transition its background-color from red to black.
Here is the code snippet for my html and css:
body {
margin: 0;
}
.example1 {
margin: auto;
margin-top: 100px;
width: 200px;
height: 200px;
background-color: red;
transition: all 1s linear;
-moz-transition: all 1s linear;
-o-transition: all 1s linear;
-webkit-transition: all 1s linear;
}
.example1:hover {
background-color: black;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Test Page</title>
<link rel="stylesheet" href="transitions.css" />
<link rel="stylesheet" href="normalize.css" />
</head>
<body>
<div class="example1"></div>
</body>
</html>
This demonstrates the outcome: https://youtu.be/5whZpt0YR68
The color transition functions as intended, but when the html file is opened, the div element slides down from the top of the body until it reaches its final position (unanticipated movement). This behavior is observed in Google Chrome, Opera, and Microsoft Edge, but not Firefox.
Any insights on why this anomaly might be occurring?