Невозможно заставить работать анимацию при наведении CSS - PullRequest
0 голосов
/ 20 января 2020

Я пытаюсь создать состояние наведения для этих кнопок с помощью преобразования и перехода, но это не сработает. Это потому, что у меня уже есть анимация для появления кнопок? Я не выбираю элемент правильно. Что я делаю неправильно?

.hero-content {
  text-align: center;
  margin: 20% auto;
}

.hero-content li {
  display: inline-block;
}

.hero-content a {
  display: block;
  width: 200px;
  background-color: red;
  margin-right: 20px;
  text-align: center;
  border-radius: 5px;
  transition: .5s;
}

.hero-content a {
  text-decoration: none;
}

.hero-content span {
  display: inline-block;
  margin: 40% 0;
  font-family: Sans-Serif;
  font-size: 1.3em;
  font-weight: 900;
  color: #fff;
}

.feat-btn {
  animation-name: feat-fly;
  animation-duration: 1s;
  animation-fill-mode: both;
  animation-timing-function: cubic-bezier(0, 0, .19, 1);
}

.box-one {
  animation-delay: 1s;
}

.box-two {
  animation-delay: 1.25s;
}

.box-three {
  animation-delay: 1.5s;
}

.box-four {
  animation-delay: 1.75s;
}

@keyframes feat-fly {
  from {
    transform: translateY(800px)
  }
  to {
    transform: translateY(0)
  }
}

.hero-content a:hover {
  transform: translateY(-20px);
}
<ul class="hero-content">
  <li>
    <a href="#" class="feat-btn box-one">
      <span>Web &amp; App</span>
    </a>
  </li>
  <li>
    <a href="#" class="feat-btn box-two">
      <span>Design</span>
    </a>
  </li>
  <li>
    <a href="#" class="feat-btn box-three">
      <span>Film &amp; Video</span>
    </a>
  </li>
  <li>
    <a href="#" class="feat-btn box-four">
      <span>Marketing</span>
    </a>
  </li>
</ul>

Может быть, я даже смогу немного почистить CSS. Я не уверен, вероятно, нет. Я бы предпочел оставить большую часть того же самого и все еще быть в состоянии решить проблему, с которой я сталкиваюсь, но любые предложения приветствуются, но я действительно хочу решить проблему перетаскивания, которую я описал выше.

Заранее спасибо !

Ответы [ 2 ]

1 голос
/ 20 января 2020

Вы ищете это?

.hero-content {
  text-align: center;
  margin: 20% auto;
}

.hero-content li {
  display: inline-block;
}

.hero-content a {
  display: block;
  width: 200px;
  background-color: red;
  margin-right: 20px;
  text-align: center;
  border-radius: 5px;
  transition:.5s;
}

.hero-content a {
  text-decoration: none;
}

.hero-content span {
 display: inline-block;
 margin: 40% 0;
 font-family: Sans-Serif; 
 font-size: 1.3em;
 font-weight: 900; 
 color: #fff;

}

.feat-btn {
  animation-name: feat-fly;
  animation-duration: 1s;
  animation-fill-mode: both;
  animation-timing-function: cubic-bezier(0,0,.19,1);

}

.box-one {
  animation-delay: 1s;
}

.box-two {
  animation-delay: 1.25s;
}

.box-three {
  animation-delay: 1.5s;
}

.box-four {
  animation-delay: 1.75s;
}

@keyframes feat-fly {
  from{ transform: translateY(800px)}
  to{ transform: translateY(0)}
}

.hero-content li:hover {
  transform: translateY(-20px);
  transition: 1s;
}
<ul class="hero-content">
      <li><a href="#" class="feat-btn box-one">
     <span>Web &amp; App</span>
    </a></li>
      <li><a href="#" class="feat-btn box-two">
      <span>Design</span>
    </a></li>
      <li><a href="#" class="feat-btn box-three">
      <span>Film &amp; Video</span> 
    </a></li>
      <li><a href="#" class="feat-btn box-four">
      <span>Marketing</span>
    </a></li>
    </ul>
1 голос
/ 20 января 2020

Если вы хотите навести указатель мыши на текст, добавьте указатель на промежуток, где находится текст. И если вы хотите добавить hover к красному полю, тогда установите hover CSS на .hero-content li: hover. Также я добавил переход для плавности. Дайте мне знать в комментариях, если есть запрос.

.hero-content {
  text-align: center;
  margin: 20% auto;
}

.hero-content li {
  display: inline-block;
  margin-bottom:20px;
}

.hero-content a {
  display: block;
  width: 200px;
  background-color: red;
  margin-right: 20px;
  text-align: center;
  border-radius: 5px;
  transition:.5s;
}

.hero-content a {
  text-decoration: none;
}

.hero-content span {
 display: inline-block;
 margin: 40% 0;
 font-family: Sans-Serif; 
 font-size: 1.3em;
 font-weight: 900; 
 color: #fff;
 transition: all 0.3s ease;

}

.feat-btn {
  animation-name: feat-fly;
  animation-duration: 1s;
  animation-fill-mode: both;
  animation-timing-function: cubic-bezier(0,0,.19,1);

}

.box-one {
  animation-delay: 1s;
}

.box-two {
  animation-delay: 1.25s;
}

.box-three {
  animation-delay: 1.5s;
}

.box-four {
  animation-delay: 1.75s;
}

@keyframes feat-fly {
  from{ transform: translateY(800px)}
  to{ transform: translateY(0)}
}

.hero-content a span:hover {
  transform: translateY(-20px);
  transition: all 0.3s ease;

}
<ul class="hero-content">
      <li><a href="#" class="feat-btn box-one">
     <span>Web &amp; App</span>
    </a></li>
      <li><a href="#" class="feat-btn box-two">
      <span>Design</span>
    </a></li>
      <li><a href="#" class="feat-btn box-three">
      <span>Film &amp; Video</span> 
    </a></li>
      <li><a href="#" class="feat-btn box-four">
      <span>Marketing</span>
    </a></li>
    </ul>
...