I tried this but it doesn't work. Each text element should change the corresponding image.
In the browser console city_name
appears as html collections
let city_name = document.getElementsByClassName("city_name");
let city_img = document.getElementsByClassName("city_img");
for (let i = 0; i < city_name.length; i++) {
city_name[i].addEventListener("mouseover", blur(i))
}
function blur(i) {
city_img[i].style.filter = "blur(4px)"
}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="style.css">
<script src="API.js"></script>
<title>WeatherLike</title>
</head>
<body>
<div class="top_city">
<div class="city">
<img src="milano.jpg" class="city_img">
<h1 class="city_name">Milano</h1>
</div>
<div class="city">
<img src="torino.jpg" class="city_img">
<h1 class="city_name">Torino</h1>
</div>
<div class="city">
<img src="bologna.jpg" class="city_img">
<h1 class="city_name">Bologna</h1>
</div>
<div class="city">
<img src="firenze.jpg" class="city_img">
<h1 class="city_name">Firenze</h1>
</div>
<div class="city">
<img src="roma.jpg" class="city_img">
<h1 class="city_name">Roma</h1>
</div>
<div class="city">
<img src="napoli.jpg" class="city_img">
<h1 class="city_name">Napoli</h1>
</div>
<div class="city">
<img src="palermo.jpg" class="city_img">
<h1 class="city_name">Palermo</h1>
</div>
</div>
</body>
</html>
Thanks.
@ChrisG @Adyson yes, ChrisG is right. But "hover the name and the image gets blurry" doesn't work in my HTML page. Maybe for the CSS?
@import url('https://fonts.googleapis.com/css2?family=Bitter:wght@700&display=swap');
*{
margin: 0;
padding: 0;
}
body{
height: 100vh;
}
.top_city{
display: flex;
flex-direction: row;
height: 20vh;
}
.city_img{
background-size: cover;
border: 1px solid lightgrey;
height: 20vh;
}
.city_name{
color: white;
text-align: center;
position: absolute;
width: 14.2%;
margin-top: 55px;
font-family: 'Bitter', serif ;
border: 1px solid rgb(255, 255, 255);
text-shadow: 1px 1px 1px black;
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0, 0.2); /* Black w/opacity/see-through */
}
.city{
overflow: hidden;
display: flex;
width: 16.66%;
}