Computer >> 컴퓨터 >  >> 프로그램 작성 >> CSS

CSS로 이미지 오버레이 호버 슬라이드 효과를 만드는 방법은 무엇입니까?


다음은 CSS로 이미지 오버레이 호버 슬라이드 효과를 만드는 코드입니다 -

예시

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.card-container {
   position: relative;
   width: 50%;
}
img {
   display: block;
   width: 100%;
}
.overlay {
   position: absolute;
   bottom: 100%;
   background-color: rgb(55, 74, 179);
   overflow: hidden;
   width: 100%;
   height: 0;
   transition: .5s ease-in-out;
}
.card-container:hover .overlay {
   bottom: 0;
   height: 100%;
}
.caption {
   color: white;
   font-size: 30px;
   position: absolute;
   top: 50%;
   left: 50%;
   text-align: center;
}
</style>
</head>
<body>
<h1>Image Overlay Slide Example</h1>
<div class="card-container">
<img src="https://i.picsum.photos/id/237/536/354.jpg">
<div class="overlay">
<div class="caption">Dog</div>
</div>
</div>
</body>
</html>

출력

위의 코드는 다음과 같은 출력을 생성합니다 -

CSS로 이미지 오버레이 호버 슬라이드 효과를 만드는 방법은 무엇입니까?

이미지 위로 마우스를 가져갈 때 -

CSS로 이미지 오버레이 호버 슬라이드 효과를 만드는 방법은 무엇입니까?