[CSS] [연습] 마우스 오버하면 상품 정보 표시하기

선영·2022년 9월 16일
0

CSS

목록 보기
21/21
post-thumbnail

product-result.html

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>마우스 오버하면 상품 정보 표시하기</title>
    <link rel="stylesheet" href="../11/css/product-result.css">
</head>
<body>
    <div id="container">
        <h1>신상품 목록</h1>
        <ul class="prod-list">
            <li>
                <img src="../11/images/prod1.jpg">
                <div class="caption">
                    <h2>상품 1</h2>
                    <p>상품 1 설명 테스트</p>
                    <p>가격 : 10,000원</p>
                </div>
            </li>
            <li>
                <img src="../11/images/prod2.jpg">
                <div class="caption">
                    <h2>상품 2</h2>
                    <p>상품 2 설명 테스트</p>
                    <p>가격 : 10,000원</p>
                </div>
            </li>
            <li>
                <img src="../11/images/prod3.jpg">
                <div class="caption">
                    <h2>상품 3</h2>
                    <p>상품 3 설명 테스트</p>
                    <p>가격 : 10,000원</p>
                </div>
            </li>
        </ul>
    </div>
</body>
</html>

css/product-result.css

#container {
  width:1000px;
  margin:20px auto;
  }
  h1 {
    text-align:center;
  }
  .prod-list {
    list-style:none;
    padding:0;
  }
  .prod-list li {
    float: left;
    padding: 0;
    margin: 10px;
    overflow: hidden;
    position: relative;
  }
  .prod-list img {
    margin:0;
    padding:0;
    float:left;
    z-index:5;
  } 
  .prod-list .caption {
    position: absolute;
    top:200px;  /* 기준 위치보다 200px 아래로 */
    width:300px;
    height:200px;
    padding-top:20px;
    background:rgba(0,0,0,0.6);  /* 반투명한 검정 배경 */ 
    opacity:0;  /* 화면에 보이지 않게 */ 
    transition: all 0.6s ease-in-out;  /* 나타날 때 부드럽게 트랜지션 추가 */
    z-index:10;  /* 다른 요소보다 위에 있도록 */ 
  }
  .prod-list li:hover .caption {
    opacity: 1;  /* 설명글이 화면에 보이게 */ 
    transform: translateY(-200px);  /* 설명글이 위로 200px 이동하게 */
  }  
  .prod-list .caption h2, .prod-list .caption p {
    color: #fff;
    text-align: center;
  }      

0개의 댓글

관련 채용 정보