잡동사니

반응형

질문

호버 애니메이션 button을 만들려고하는데 앵커 태그에 display : block 을 써도 div를 클릭해도 작동하지 않는 이유를 모르겠습니다.
아래는 내 HTML 및 CSS 코드도 jsfiddle입니다.

HTML :

<div class="animation-button">
  <div class="raised hoverable">
    <div class="anim"></div><span><a href="index.php?option=com_content&view=about&Itemid=104">More About Us</a></span>
  </div>
</div>

CSS :

.animation-button .raised {
  position: relative;
  margin: 1em;
  font-weight: 100;
  padding: 10px 19px;
  text-align: center;
  //min-width:14%;
  /*width: 200px;*/
  /*border-radius: 5px;*/
  overflow: hidden;
  position: relative;
  z-index: 0;
  cursor: pointer;
  display: inline-block;
}
.animation-button .raised {
  -moz-transition: all 0.1s;
  -o-transition: all 0.1s;
  -webkit-transition: all 0.1s;
  transition: all 0.1s;
  background: #849C8E;
  box-shadow: 0px 1px 1px #849C8E;
}
.animation-button .raised:active {
  background: #70897A;
  box-shadow: 0px 1px 1px #70897A;
  /* display: inline-block; */
}

.animation-button .raised span a {
  font-weight: 400;
  font-size: 3vw;
  color: #fff;
  text-decoration: none;
  display: block;
}

.animation-button span a:hover,#ankur span a:focus{
    color: #fff;
    display: block;
}

.anim {
  -moz-transform: translateY(-50%) translateX(-50%);
  -ms-transform: translateY(-50%) translateX(-50%);
  -webkit-transform: translateY(-50%) translateX(-50%);
  transform: translateY(-50%) translateX(-50%);
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: -1;
}
.anim:before {
  position: relative;
  content: '';
  display: block;
  margin-top: 100%;
}
.anim:after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 50%;
}

.hoverable:hover > .anim {
  -moz-animation: anim-out 0.75s;
  -webkit-animation: anim-out 0.75s;
  animation: anim-out 0.75s;
}
.hoverable:hover > .anim:after {
  -moz-animation: anim-out-pseudo 0.75s;
  -webkit-animation: anim-out-pseudo 0.75s;
  animation: anim-out-pseudo 0.75s;
}

@-webkit-keyframes anim-in {
  0% {
    width: 0%;
  }
  100% {
    width: 100%;
  }
}
@-moz-keyframes anim-in {
  0% {
    width: 0%;
  }
  100% {
    width: 100%;
  }
}
@-ms-keyframes anim-in {
  0% {
    width: 0%;
  }
  100% {
    width: 100%;
  }
}
@keyframes anim-in {
  0% {
    width: 0%;
  }
  100% {
    width: 100%;
  }
}
@-webkit-keyframes anim-in-pseudo {
  0% {
    background: rgba(0, 0, 0, 0.25);
  }
  100% {
    background: transparent;
  }
}
@-moz-keyframes anim-in-pseudo {
  0% {
    background: rgba(0, 0, 0, 0.25);
  }
  100% {
    background: transparent;
  }
}
@-ms-keyframes anim-in-pseudo {
  0% {
    background: rgba(0, 0, 0, 0.25);
  }
  100% {
    background: transparent;
  }
}
@keyframes anim-in-pseudo {
  0% {
    background: rgba(0, 0, 0, 0.25);
  }
  100% {
    background: transparent;
  }
}
@-webkit-keyframes anim-out {
  0% {
    width: 0%;
  }
  100% {
    width: 100%;
  }
}
@-moz-keyframes anim-out {
  0% {
    width: 0%;
  }
  100% {
    width: 100%;
  }
}
@-ms-keyframes anim-out {
  0% {
    width: 0%;
  }
  100% {
    width: 100%;
  }
}
@keyframes anim-out {
  0% {
    width: 0%;
  }
  100% {
    width: 100%;
  }
}
@-webkit-keyframes anim-out-pseudo {
  0% {
    background: rgba(0, 0, 0, 0.25);
  }
  100% {
    background: transparent;
  }
}
@-moz-keyframes anim-out-pseudo {
  0% {
    background: rgba(0, 0, 0, 0.25);
  }
  100% {
    background: transparent;
  }
}
@-ms-keyframes anim-out-pseudo {
  0% {
    background: rgba(0, 0, 0, 0.25);
  }
  100% {
    background: transparent;
  }
}
@keyframes anim-out-pseudo {
  0% {
    background: rgba(0, 0, 0, 0.25);
  }
  100% {
    background: transparent;
  }
}

jsfiddle : https://jsfiddle.net/a2zgk/yL8ngrx5/1/


답변1

링크가 다음과 같이 button의 전체 영역을 포함하도록 button대신 a태그에 패딩을 추가합니다.

.animation-button .raised {
  position: relative;
  margin: 1em;
  font-weight: 100;
  text-align: center;
  //min-width:14%;
  /*width: 200px;*/
  /*border-radius: 5px;*/
  overflow: hidden;
  position: relative;
  z-index: 0;
  cursor: pointer;
  display: inline-block;
}

.animation-button .raised {
  -moz-transition: all 0.1s;
  -o-transition: all 0.1s;
  -webkit-transition: all 0.1s;
  transition: all 0.1s;
  background: #849C8E;
  box-shadow: 0px 1px 1px #849C8E;
}

.animation-button .raised:active {
  background: #70897A;
  box-shadow: 0px 1px 1px #70897A;
  /* display: inline-block; */
}

.animation-button .raised span a {
  font-weight: 400;
  font-size: 3vw;
  color: #fff;
  text-decoration: none;
  display: block;
  padding: 10px 19px;
}

.animation-button span a:hover,
#ankur span a:focus {
  color: #fff;
  display: block;
}

.anim {
  -moz-transform: translateY(-50%) translateX(-50%);
  -ms-transform: translateY(-50%) translateX(-50%);
  -webkit-transform: translateY(-50%) translateX(-50%);
  transform: translateY(-50%) translateX(-50%);
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: -1;
}

.anim:before {
  position: relative;
  content: '';
  display: block;
  margin-top: 100%;
}

.anim:after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 50%;
}

.hoverable:hover>.anim {
  -moz-animation: anim-out 0.75s;
  -webkit-animation: anim-out 0.75s;
  animation: anim-out 0.75s;
}

.hoverable:hover>.anim:after {
  -moz-animation: anim-out-pseudo 0.75s;
  -webkit-animation: anim-out-pseudo 0.75s;
  animation: anim-out-pseudo 0.75s;
}

@-webkit-keyframes anim-in {
  0% {
    width: 0%;
  }
  100% {
    width: 100%;
  }
}

@-moz-keyframes anim-in {
  0% {
    width: 0%;
  }
  100% {
    width: 100%;
  }
}

@-ms-keyframes anim-in {
  0% {
    width: 0%;
  }
  100% {
    width: 100%;
  }
}

@keyframes anim-in {
  0% {
    width: 0%;
  }
  100% {
    width: 100%;
  }
}

@-webkit-keyframes anim-in-pseudo {
  0% {
    background: rgba(0, 0, 0, 0.25);
  }
  100% {
    background: transparent;
  }
}

@-moz-keyframes anim-in-pseudo {
  0% {
    background: rgba(0, 0, 0, 0.25);
  }
  100% {
    background: transparent;
  }
}

@-ms-keyframes anim-in-pseudo {
  0% {
    background: rgba(0, 0, 0, 0.25);
  }
  100% {
    background: transparent;
  }
}

@keyframes anim-in-pseudo {
  0% {
    background: rgba(0, 0, 0, 0.25);
  }
  100% {
    background: transparent;
  }
}

@-webkit-keyframes anim-out {
  0% {
    width: 0%;
  }
  100% {
    width: 100%;
  }
}

@-moz-keyframes anim-out {
  0% {
    width: 0%;
  }
  100% {
    width: 100%;
  }
}

@-ms-keyframes anim-out {
  0% {
    width: 0%;
  }
  100% {
    width: 100%;
  }
}

@keyframes anim-out {
  0% {
    width: 0%;
  }
  100% {
    width: 100%;
  }
}

@-webkit-keyframes anim-out-pseudo {
  0% {
    background: rgba(0, 0, 0, 0.25);
  }
  100% {
    background: transparent;
  }
}

@-moz-keyframes anim-out-pseudo {
  0% {
    background: rgba(0, 0, 0, 0.25);
  }
  100% {
    background: transparent;
  }
}

@-ms-keyframes anim-out-pseudo {
  0% {
    background: rgba(0, 0, 0, 0.25);
  }
  100% {
    background: transparent;
  }
}

@keyframes anim-out-pseudo {
  0% {
    background: rgba(0, 0, 0, 0.25);
  }
  100% {
    background: transparent;
  }
}
<div class="animation-button">
  <div class="raised hoverable">
    <div class="anim"></div><span><a href="index.php?option=com_content&view=about&Itemid=104">More About Us</a></span>
  </div>
</div>



 

 

 

 

출처 : https://stackoverflow.com/questions/47605757/button-div-not-clickable-only-work-if-i-click-on-text-tried-everything-nothing-w

반응형

이 글을 공유합시다

facebook twitter googleplus kakaoTalk kakaostory naver band