HTML (index.html)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D Social Media Button</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<div class="social-media-button" id="socialButton">
<span>SUBSCRIBE US</span>
</div>
</div>
<script src="scripts.js"></script>
</body>
</html>
CSS (styles.css)
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f2f5;
font-family: Arial, sans-serif;
}
.container {
perspective: 1000px;
}
.social-media-button {
display: flex;
justify-content: center;
align-items: center;
width: 200px;
height: 60px;
background-color: #ff0000;
color: white;
font-size: 1.5em;
border-radius: 10px;
cursor: pointer;
transform-style: preserve-3d;
transition: transform 0.3s ease-in-out;
box-shadow: 0 8px 15px rgba(0, 0, 0, 0.1);
}
.social-media-button:hover {
transform: rotateX(20deg) rotateY(20deg);
}
.social-media-button span {
position: relative;
z-index: 2;
}
.social-media-button:before {
content: '';
position: absolute;
width: 100%;
height: 100%;
background-color: #b30000;
top: 0;
left: 0;
border-radius: 10px;
transform: translateZ(-20px);
transition: transform 0.3s ease-in-out;
}
.social-media-button:hover:before {
transform: translateZ(0);
}
JavaScript (scripts.js)
document.getElementById('socialButton').addEventListener('click', function() {
alert('Thank you for following us!');
});
Explanation
HTML:
- The HTML file contains a simple structure with a
div
element for the social media button. Theid
attribute is used to reference the button in the JavaScript file.
- The HTML file contains a simple structure with a
CSS:
- Styles the body to center the button on the page.
- Defines a container with perspective to create the 3D effect.
- The
.social-media-button
class styles the button with dimensions, background color, font size, and border-radius. - The
transform
andtransition
properties are used to create the 3D rotation effect on hover. - The
:before
pseudo-element is used to create a 3D depth effect behind the button.
JavaScript:
- Adds an event listener to the button, triggering an alert message when the button is clicked.
Usage
- Create three files:
index.html
,styles.css
, andscripts.js
. - Copy the respective code into these files.
- Open
index.html
in your browser to see the 3D animated social media button.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D Social Media Buttons</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="social-buttons">
<a href="https://www.facebook.com" class="social-button facebook" target="_blank">
<i class="fab fa-facebook-f"></i>
</a>
<a href="https://www.twitter.com" class="social-button twitter" target="_blank">
<i class="fab fa-twitter"></i>
</a>
<a href="https://www.instagram.com" class="social-button instagram" target="_blank">
<i class="fab fa-instagram"></i>
</a>
<a href="https://www.linkedin.com" class="social-button linkedin" target="_blank">
<i class="fab fa-linkedin-in"></i>
</a>
<a href="https://www.youtube.com" class="social-button youtube" target="_blank">
<i class="fab fa-youtube"></i>
</a>
</div>
<script src="https://kit.fontawesome.com/a076d05399.js" crossorigin="anonymous"></script>
<script src="scripts.js"></script>
</body>
</html>
css:
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f0f2f5;
margin: 0;
}
.social-buttons {
display: flex;
gap: 20px;
}
.social-button {
display: flex;
justify-content: center;
align-items: center;
width: 60px;
height: 60px;
border-radius: 50%;
color: #fff;
text-decoration: none;
font-size: 24px;
transition: transform 0.3s;
box-shadow: 0 10px 20px rgba(0,0,0,0.2);
}
.social-button:hover {
transform: rotateY(360deg);
}
.facebook {
background-color: #3b5998;
}
.twitter {
background-color: #1da1f2;
}
.instagram {
background: radial-gradient(circle at 30% 107%, #fdf497 0%, #fdf497 5%, #fd5949 45%, #d6249f 60%, #285aeb 90%);
}
.linkedin {
background-color: #0077b5;
}
.youtube {
background-color: #ff0000;
}
0 Comments