• 카테고리

    질문 & 답변
  • 세부 분야

    웹 개발

  • 해결 여부

    미해결

hover했다가 마우스를 뗐을 때

22.03.16 18:08 작성 조회수 680

1

영상을 먼저 보고 스스로 만드는 도중에 거슬리는 부분이 있어 질문드립니다.

마우스를 item에 hover하다가 뗐을 때

back부분의 텍스트가 잔상처럼 남다가 사라집니다.

hover했다가 떼는 순간에 back부분은 없어지게 하는 방법은 없을까요?(영상에선 hover했다가 떼는 순간에 슬라이드되는 것처럼 back부분이 없어지는데 뭐가 문젠지 모르겠습니다) back에 transition을 주지 않으면 back부분이 단순히 생겼다 사라져서 문제를 해결할 수는 있지만 front부분처럼 슬라이드되는 느낌이 없어져서요.

투명도 문제인가해서 front부분에 투명도를 아예 없애봤지만 잔상처럼 잠깐 남았다가 사라져서 시각적으로 보기 불편합니다. 어떻게 해앟ㄹ까요? 아래가 css소스코드입니다.

 

 

 

 

 

@import url('https://fonts.googleapis.com/css2?family=Nanum+Gothic&display=swap');
@keyframes bigger-animation {
  0% {
    transform: scale(80%);
  }
  100% {
    transform: scale(110%);
  }
}
body {
  font-family: 'Nanum Gothic', sans-serif;
  font-size: 13px;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0;
  background-color: #4c6ef5;
}
.items{
  display: flex;
  flex-wrap: wrap;
  width: 900px;
  justify-content: space-evenly;
}
a{
  text-decoration: none;
  color: black;
}
.item {
  width: 250px;
  height: 200px;
  text-align: center;
  position: relative;
  border-radius: 10px;
}
.front{
  width: 100%;
  height: inherit;
  position: absolute;
  top: 0;
  z-index: 1;
  box-shadow: 0 0 13px #91a7ff;
  transition: .2s;
}
.item:hover .front , .back {
  background-color: rgba(186, 200, 255, .7);
}
.item:hover .front{
  top:-50%;
  box-shadow: none;
  border-radius: 10px 10px 0 0;
  border-bottom: 1px solid rgba(0,0,0,.5);
}
.item:hover .front img {
  animation: bigger-animation .4s linear infinite alternate;
}
.item:hover .back{
  top:50%;
  opacity: 1;
  border-radius: 0 0 10px 10px;
}
.front h3{
  margin: 0;
  padding: 0;
}
.back{
  width: 100%;
    height: inherit;
    line-height: 1.5em;
    position:absolute;
    padding: 20px;
    box-sizing: border-box;
    opacity: 0;
    transition: .2s;
}
.back p{
  margin: 3px 8px;
}
.back a{
  display: inline-block;
  margin-top: 10px;
  padding: 3px 8px;
  background-color: #748ffc;
  border-radius: 3px;
}

답변 3

·

답변을 작성해보세요.

0

이부분은 .front가 .back을 완벽하게 가리지는 못하는 것 같습니다.

그래서 .back에 opacity: 0 주고 hover하면 .back에 opacity: 1로 주면 잔상을 없앨 수 있습니다. 

낭니님의 프로필

낭니

질문자

2022.03.20

이미 css에서 .back에 opacity:0을 주고 .item:hover . back{}에 opacity:1을 주었었습니다 위에 css코드에 일부 다시 복사해서 붙여넣었습니다 ㅠ

.back부분에 transition을 주지 않으면 잔상이 안 남는데, 그러면 front가 올라가면서 back이 그냥 띡하고 올라오는 것같아서 시각적으로 보기 안좋아서요.. 왜 그럴까요.. opacity는 해결책이 아닌 것 같습니다

.item:hover .back{
  top:50%;
  opacity: 1;
  border-radius: 0 0 10px 10px;
}
.front h3{
  margin: 0;
  padding: 0;
}
.back{
  width: 100%;
    height: inherit;
    line-height: 1.5em;
    position:absolute;
    padding: 20px;
    box-sizing: border-box;
    opacity: 0;
    transition: .2s;
}

0

낭니님의 프로필

낭니

질문자

2022.03.17

 

 

아래가 html소스코드입니다. 그리고 아래 질문도 답변 부탁드립니다

호버했다가 떼는 순간에 보이는 back부분 텍스트 잔상이라 스크린샷하기가 어렵습니다.

 

 

 

<!DOCTYPE html>
<html lang="ko">
  <head>
    <meta charset="utf-8">
    <title>hover Example 4</title>
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <div class="items">
      <div class="item">
        <div class="front">
          <img src="img/space-01.png">
          <h3>Mars</h3>
        </div>
        <div class="back">
          <p>화성은 태양계의 네 번째 행성이다. 4개의 지구형 행성 중 하나다. 동양권에서는 불을 뜻하는 화(火)를 써서 화성이라 부르고 로마 신화의 전쟁의 신 마르스의 이름을 따 Mars라 부른다.</p>
          <a href="#none">Read More</a>
        </div>
      </div>
      <div class="item">
        <div class="front">
          <img src="img/space-02.png">
          <h3>Jupiter</h3>
        </div>
        <div class="back">
          <p>목성은 태양계의 다섯번째 행성이자 가장 큰 행성이다. 태양의 질량의 천분의 일배에 달하는 거대행성으로, 태양계에 있는 다른 모든 행성들을 합한 질량의 약 2.5배에 이른다.</p>
          <a href="#none">Read More</a>
        </div>
      </div>
      <div class="item">
        <div class="front">
          <img src="img/space-03.png">
          <h3>Saturnus</h3>
        </div>
        <div class="back">
          <p>토성은 태양으로부터 여섯 번째에 있는 태양계의 행성으로, 진성(鎭星)으로도 불렀다. 토성은 태양계 내의 행성 중 목성에 이어 두 번째로 크며, 지름은 약 12만 킬로미터이다.</p>
          <a href="#none">Read More</a>
        </div>
      </div>
    </div>
  </body>
</html>

0

html이 조금이라도 다르면 다른 결과를 내기 때문에 html 코드도 항상 같이 올려주세요.

그리고 스크린샷으로 보여지시는게 확실합니다.

낭니님의 프로필

낭니

질문자

2022.03.19

<!DOCTYPE html>
<html lang="ko">
  <head>
    <meta charset="utf-8">
    <title>hover Example 4</title>
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <div class="items">
      <div class="item">
        <div class="front">
          <img src="img/space-01.png">
          <h3>Mars</h3>
        </div>
        <div class="back">
          <p>화성은 태양계의 네 번째 행성이다. 4개의 지구형 행성 중 하나다. 동양권에서는 불을 뜻하는 화(火)를 써서 화성이라 부르고 로마 신화의 전쟁의 신 마르스의 이름을 따 Mars라 부른다.</p>
          <a href="#none">Read More</a>
        </div>
      </div>
      <div class="item">
        <div class="front">
          <img src="img/space-02.png">
          <h3>Jupiter</h3>
        </div>
        <div class="back">
          <p>목성은 태양계의 다섯번째 행성이자 가장 큰 행성이다. 태양의 질량의 천분의 일배에 달하는 거대행성으로, 태양계에 있는 다른 모든 행성들을 합한 질량의 약 2.5배에 이른다.</p>
          <a href="#none">Read More</a>
        </div>
      </div>
      <div class="item">
        <div class="front">
          <img src="img/space-03.png">
          <h3>Saturnus</h3>
        </div>
        <div class="back">
          <p>토성은 태양으로부터 여섯 번째에 있는 태양계의 행성으로, 진성(鎭星)으로도 불렀다. 토성은 태양계 내의 행성 중 목성에 이어 두 번째로 크며, 지름은 약 12만 킬로미터이다.</p>
          <a href="#none">Read More</a>
        </div>
      </div>
    </div>
  </body>
</html>

 

html 코드입니다