To create a page with three icons that animate on hover, you'll need to set up your HTML to create the structure, use CSS for styling and animations, and potentially JavaScript if you want to add additional functionality. Below is a basic example of how you might set this up:
HTML
First, we'll create a simple HTML structure with three icons. You can use icons from a library like Font Awesome or provide your own:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Animated Icons</title>
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
</head>
<body>
<div class="icon-container">
<div class="icon">
<i class="fas fa-home"></i>
</div>
<div class="icon">
<i class="fas fa-user"></i>
</div>
<div class="icon">
<i class="fas fa-cog"></i>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
CSS
Style the icons and add hover animations using CSS:
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f4f4f9;
}
.icon-container {
display: flex;
gap: 20px;
}
.icon {
font-size: 50px;
color: #333;
transition: transform 0.3s ease, color 0.3s ease;
cursor: pointer;
}
.icon:hover {
color: #007BFF;
transform: scale(1.2) rotate(10deg);
}
JavaScript
In this case, JavaScript is optional since the hover effect is handled by CSS. However, if you want to add additional dynamic behaviors, you could do so with JavaScript. Here's a simple example that logs which icon was clicked:
document.querySelectorAll('.icon').forEach(item => {
item.addEventListener('click', event => {
console.log('Icon clicked:', event.target.classList);
});
});
Explanation
- HTML: The structure includes a container that holds three icons. Each icon is wrapped in a
div with a class of icon.
- CSS: Sets basic styles for body and icons. It adds a
hover effect to scale and rotate the icons as well as change their color.
- JavaScript: Adds an event listener to each icon that logs a message to the console when an icon is clicked.
This is a basic implementation, and you can expand upon it by adding more complex animations, different icons, or additional JavaScript functionality based on your requirements.