HTML в порядке, JS в порядке, единственное, что:
.top-section-hover img
- более конкретно c, чем .active
. Таким образом, мы всегда видим стили .top-section-hover img
.
, изменяющие .active
на .top-section-hover img.active
, делающие этот блок более конкретным c, поэтому применяются его правила
$('.cover-img').mouseover(function() {
if ($(this).hasClass('active')) return;
$('.active').removeClass('active');
$(this).addClass('active');
});
.top-section-hover {
display: flex;
padding-top: 10em;
justify-content: center;
flex-grow: 2;
text-align: center;
text-transform: uppercase;
font-weight: bold;
max-width: 96%;
}
.top-section-hover img {
position: relative;
top: 0;
transition: top ease 0.5s;
left: 0;
}
.top-section-hover img.active {
top: -30px;
transition: all 0.5s ease
}
.cover-title {
font-weight: bold;
}
.hover-cover-middle:hover .cover-title {
color: white;
border-bottom: 3px solid white;
transition: 0.5s all;
}
.hover-cover-left:hover .cover-title {
color: white;
border-bottom: 3px solid white;
transition: 0.5s all;
}
.hover-cover-right:hover .cover-title {
color: white;
border-bottom: 3px solid white;
transition: 0.5s all;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="top-section-hover">
<span class="hover-cover-left">
<a href="#" class="cover-left-content">
<img src="https://via.placeholder.com/150
C/O https://placeholder.com/" alt="" class="cover-img">
<span class="cover-title">Office</span>
</a>
</span>
<span class="hover-cover-middle">
<a href="#" class="cover-left-content">
<img src="https://via.placeholder.com/150
C/O https://placeholder.com/" alt="" class="cover-img">
<span class="cover-title">Home</span>
</a>
</span>
<span class="hover-cover-right">
<a href="#" class="cover-left-content">
<img src="https://via.placeholder.com/150
C/O https://placeholder.com/" alt="" class="cover-img">
<span class="cover-title">Events</span>
</a>
</span>
</div>