CSS에서 배경 이미지를 어둡게 하고 마우스로 강조 표시

4265 단어 CSS

배경 이미지 먼저 추가



코드
<a href="#">
    <div class="menu">
        <div class="box">
            ここに文章があったり。
        </div>
    </div>
</a>
먼저 CSS를 통해 배경을 어둡게 만듭니다.
CSS 코드
.menu {
    height: 100px;
    background: url(fruits.jpg) center no-repeat;
    background-size: cover; 

    position: relative;
    height:100%;
}

.box {
    position: absolute;
    width: 100%;
    top: 45%;

    text-align: center;
    color: #FFF;
}

배경 이미지를 어둡게 만들기



배경 요소에 CSS에서 어두워진 요소 이미지 추가하기
.menu::before{
    background-color: rgba(0,0,0,0.3);
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    content: ' ';
}

마우스가 지나가자마자 밝아졌다



삽입된 CSS만 열기
a:hover .menu::before{
    background-color: rgba(0,0,0,0);
}

좋은 웹페이지 즐겨찾기