in my class we have a server where we put all of our web projects, but the main page is the default one, and my teacher asked me to create a "landing place" something like that. Ive created something normal but I want to make it better, i have the normal page with buttons but when i have my mouse over i wanted it to appear a picture of each one of us. Its working but the image just appears with no animation and I cant change it, i cant even center vertically this. I was wondering if someone could help me..
Please don´t judge me, I am new to this and i´m trying to learn.
To center vertically, I literally tried applied all center properties and still didn´t worked.
For the image, I tried a opacity transition and to keep up with the button I tried a translateY 10px to keep it with it.
The white picture is just a test, later I will change it to the real ones.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css" type="text/css">
<title>11TGPSI</title>
</head>
<body>
<div id="header">
<div class="logo">11TGPSI.</div>
<div class="container">
<div class="line">
<a href="">
<div class="number">Nº 1</div>
<div class="name">Afonso Nabeto</div>
<div class="image"><img src="./images/personIcon.png" height="120"></div>
</a>
<a href="">
<div class="number">Nº 2</div>
<div class="name">Bianca Silva</div>
<div class="image"><img src="./images/personIcon.png" height="120"></div>
</a>
<a href="">
<div class="number">Nº 3</div>
<div class="name">Duarte Rocha</div>
<div class="image"><img src="./images/personIcon.png" height="120"></div>
</a>
<a href="">
<div class="number">Nº 4</div>
<div class="name">Guilherme Costa</div>
<div class="image"><img src="./images/personIcon.png" height="120"></div>
</a>
</div>
<div class="line">
<a href="">
<div class="number">Nº 5</div>
<div class="name">Hugo Silva</div>
<div class="image"><img src="./images/personIcon.png" height="120"></div>
</a>
<a href="">
<div class="number">Nº 6</div>
<div class="name">Joana Rita</div>
<div class="image"><img src="./images/personIcon.png" height="120"></div>
</a>
<a href="">
<div class="number">Nº 7</div>
<div class="name">João Teixeira</div>
<div class="image"><img src="./images/personIcon.png" height="120"></div>
</a>
<a href="">
<div class="number">Nº 8</div>
<div class="name">João Ladeira</div>
<div class="image"><img src="./images/personIcon.png" height="120"></div>
</a>
</div>
<div class="line">
<a href="">
<div class="number">Nº 9</div>
<div class="name">Keila Mendes</div>
<div class="image"><img src="./images/personIcon.png" height="120"></div>
</a>
<a href="">
<div class="number">Nº 10</div>
<div class="name">Leonardo Melendre</div>
<div class="image"><img src="./images/personIcon.png" height="120"></div>
</a>
<a href="">
<div class="number">Nº 11</div>
<div class="name">Lucas Diniz</div>
<div class="image"><img src="./images/personIcon.png" height="120"></div>
</a>
<a href="">
<div class="number">Nº 12</div>
<div class="name">Marlom Silva</div>
<div class="image"><img src="./images/personIcon.png" height="120"></div>
</a>
</div>
<div class="line">
<a href="">
<div class="number">Nº 13</div>
<div class="name">Miguel Lourenço</div>
<div class="image"><img src="./images/personIcon.png" height="120"></div>
</a>
<a href="">
<div class="number">Nº 14</div>
<div class="name">Ruben Magalhães</div>
<div class="image"><img src="./images/personIcon.png" height="120"></div>
</a>
<a href="">
<div class="number">Nº 15</div>
<div class="name">Tomé Almeida</div>
<div class="image"><img src="./images/personIcon.png" height="120"></div>
</a>
<a href="">
<div class="number">Nº 16</div>
<div class="name">Ygor Mendonça</div>
<div class="image"><img src="./images/personIcon.png" height="120"></div>
</a>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function () {
const links = document.querySelectorAll('a');
links.forEach(link => {
link.addEventListener('mouseover', function () {
const image = link.querySelector('.image');
image.classList.add('image-active');
});
link.addEventListener('mouseout', function () {
const image = link.querySelector('.image');
image.classList.remove('image-active');
});
});
});
</script>
</body>
</html>
CSS
@import url('https://fonts.googleapis.com/css?family=Poppins:700|Poppins:400');
:root {
--text: #ebe7e5;
--background: #0c0a09;
--primary: #8c9fa6;
--secondary: #0b0c0e;
--accent: #64827b;
}
* {
font-family: Poppins;
margin: 0;
padding: 0;
}
#header {
width: 100%;
height: 100vh;
background-color: var(--background);
}
.logo {
color: var(--text);
font-size: 40px;
font-weight: bold;
height: 60px;
margin-left: 15px;
}
.container {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.line {
display: flex;
}
a {
background-color: none;
color: var(--text);
width: 200px;
height: 70px;
margin: 20px;
border-radius: 8px;
text-decoration: none;
border: 1px solid;
transition: 0.8s;
}
a:hover {
height: 200px;
background: var(--text);
color: var(--secondary);
}
.number {
font-weight: bold;
font-size: 28px;
margin-left: 8px;
}
.name {
font-size: 18px;
margin-left: 8px;
}
.image {
display: none;
justify-content: center;
margin-top: 10px;
}
.image-active {
display: flex;
}
2
Answers
First of all I have to suggest you that using add and remove class is no longer a good way to give active styles, instead you can simple use toggle to add/remove class in events.
Secondly, you can chane
transition: 0.8s;
totransition: 0.8s ease-in-out;
to have a slow start and end.If you want to center image vertically it is better to change height of the
<a></a>
tag when hovered, to 220px.}