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

CSS로 마우스를 가져갈 때 이미지 오버레이 제목을 만드는 방법은 무엇입니까?

<시간/>

다음은 CSS를 사용하여 마우스 오버 시 이미지 오버레이 제목을 만드는 코드입니다 -

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {box-sizing: border-box;}
.card-container {
   position: relative;
   width: 50%;
}
.image {
   display: block;
   width: 100%;
   height: auto;
}
.overlay {
   position: absolute;
   bottom: 0;
   background: rgba(48, 9, 155, 0.5);
   width: 78%;
   transition: .5s ease;
   opacity:0;
   color: rgb(251, 255, 0);
   font-size: 25px;
   font-weight: bolder;
   padding: 20px;
   text-align: center;
}
.card-container:hover .overlay {
   opacity: 1;
}
</style>
</head>
<body>
<h2>Image Overlay Title Example</h2>
<div class="card-container">
<img src="https://i.picsum.photos/id/237/536/354.jpg" >
<div class="overlay">Dog</div>
</div>
</body>
</html>

출력

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

CSS로 마우스를 가져갈 때 이미지 오버레이 제목을 만드는 방법은 무엇입니까?

이미지 위로 마우스를 가져가면 캡션이 아래쪽으로 표시됩니다 -

CSS로 마우스를 가져갈 때 이미지 오버레이 제목을 만드는 방법은 무엇입니까?