작성
·
388
답변 2
0
<!DOCTYPE html>
<html lang="en">
<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>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<link rel="stylesheet" href="style-background.css" />
</head>
<body>
<div class="container">
<ul class="navi">
<li data-img="./images/portrait-01.jpg">
<a href="#none" data-txt="ABOUT">ABOUT</a>
</li>
<li data-img="./images/portrait-02.jpg">
<a href="#none" data-txt="INSTRUCTOR">INSTRUCTOR</a>
</li>
<li data-img="./images/portrait-03.jpg">
<a href="#none" data-txt="CLASS">CLASS</a>
</li>
<li data-img="./images/portrait-04.jpg">
<a href="#none" data-txt="LOCATION">LOCATION</a>
</li>
</ul>
<div class="photo"></div>
</div>
<script>
$(".navi li").mouseenter(function () {
var dataImg = $(this).attr("data-img");
$(".photo").css({ "background-image": "url(" + dataImg + ")" });
});
$(".navi li").mouseleave(function () {
$(".photo").css({ "background-image": ''});
});
</script>
</body>
</html>
안녕하세요~
html과 css 파일 코드 올립니다.
감사합니다~
@charset 'utf-8';
/* Fontawesome 4.7 */
@import url("https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css");
@import url("https://fonts.googleapis.com/css2?family=Monoton&display=swap");
@import url("https://fonts.googleapis.com/css2?family=Montserrat&display=swap");
@import url("https://fonts.googleapis.com/css2?family=Raleway&display=swap");
body {
margin: 0;
font-family: 'Raleway', sans-serif;
/* background-color: #000; */
}
ul{list-style: none; padding: 0; margin: 0;}
.navi{}
.navi {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 100;
}
.navi li{}
.navi li a{
font-size: 4em;
/* font-weight: bold; */
text-decoration: none;
color: #fff;
position: relative;
}
.navi li a::after{
content: attr(data-txt);
position: absolute;
color: blueviolet;
top: 0;
left: 0;
width: 0;
overflow: hidden;
transition: 0.5s;
z-index: 10;
}
.navi li a:hover:after{
width: 100%;
}
.photo{
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-image: url(./images/portrait-initial.jpg);
background-repeat: no-repeat;
background-size: cover;
background-position: center center;
transition: 0.5s;
}
0
올려주신 코드로 확인해봤는데 저는 정상적으로 나오는데요.
링크하신 웹폰트 다른 것들로 해도 괜찮더라구요.
이런 경우 혹시 폰트 종류에 따른 줄 간격 때문일 수 있어요.
그래서 .navi li a 여기에 line-height: 0 줘보세요.