Css анимация и выпадающая навигация с Bootstrap 4 - PullRequest
0 голосов
/ 09 октября 2018

html-код

<section class="container-fluid">
  <div class="col">
    <div class="row justify-content-md-center">
      <div class="col nav-color card-border">
        <ul class="nav nav-pills">
          <li class="container-custom topBotomBordersIn dropdown">
            <button class="btn-custom-animated dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">nav1dropdown</button>
            <div class="dropdown-menu">
              <button class="btn-custom-animated">dropdown1</button> 
              <button class="btn-custom-animated">dropdown2</button> 
              <button class="btn-custom-animated">dropdown3</button> 
            </div>                
          </li>
          <li class="container-custom topBotomBordersIn">
            <button class="btn-custom-animated">nav2</button> 
            <button class="btn-custom-animated">nav3</button> 
          </li>
        </ul>
      </div>
    </div>
  </div>
</section>

css-код

.center-pills {
  display: flex;
  justify-content: center;
}
.nav-color {
  background-color:deepskyblue;
}
.dropdown-menu {
  background-color: deepskyblue !important;
}
.btn-custom-animated {
  background-color: transparent;
  border: none;
  box-shadow: none;
  outline: none;
}
.btn-custom-animated.active.focus,
.btn-custom-animated.active:focus,
.btn-custom-animated.focus,
.btn-custom-animated.focus:active,
.btn-custom-animated:active:focus,
.btn-custom-animated:focus {
  outline: 0 !important;
  outline-offset: 0 !important;
  background-image: none !important;
  -webkit-box-shadow: none !important;
  box-shadow: none !important;
  background-color: transparent;
  border: none;
  box-shadow: none;
  outline: none;
}
li.container-custom {
  font-family: Raleway;
  margin: 0 auto;
  /*padding: 10em 3em;*/
  text-align: center;
}
li.container-custom button {
  color: #FFF;
  text-decoration: none;
  font: 20px Raleway;
  margin: 0px 10px;
  padding: 10px 10px;
  position: relative;
  z-index: 0;
  cursor: pointer;
}
/* Top and Bottom borders come in */
li.topBotomBordersIn button:before, li.topBotomBordersIn button:after {
  position: absolute;
  left: 0px;
  width: 100%;
  height: 2px;
  background: #FFF;
  content: "";
  opacity: 0;
  transition: all 0.3s;
}
li.topBotomBordersIn button:before {
  top: 0px;
  transform: translateY(-10px);
}
li.topBotomBordersIn button:after {
  bottom: 0px;
  transform: translateY(10px);
}
li.topBotomBordersIn button:hover:before, li.topBotomBordersIn button:hover:after {
  opacity: 1;
  transform: translateY(0px);
}

jsfiddle.net

В этом проекте я использую Bootstrap 4 со всеми плагинами js.

Я не могу понять причину, по которой первая кнопка (выпадающий список) имеет другую нижнюю строку во время анимации.В jsfiddle кнопки навигации в выпадающем списке также не работают, но в проекте они анимируются правильно.

1 Ответ

0 голосов
/ 09 октября 2018

Проблема в том, что у кнопки есть класс .dropdown-toggle, который имеет собственный CSS и элемент psuedo .dropdown-toggle:after, просто переопределите его, и он будет работать нормально.

.center-pills {
  display: flex;
  justify-content: center;
}
.nav-color {
  background-color:deepskyblue;
}
.dropdown-menu {
  background-color: deepskyblue;
}
.btn-custom-animated {
  background-color: transparent;
  border: none;
  box-shadow: none;
  outline: none;
}
.btn-custom-animated.active.focus,
.btn-custom-animated.active:focus,
.btn-custom-animated.focus,
.btn-custom-animated.focus:active,
.btn-custom-animated:active:focus,
.btn-custom-animated:focus {
  outline: 0 !important;
  outline-offset: 0 !important;
  background-image: none !important;
  -webkit-box-shadow: none !important;
  box-shadow: none !important;
  background-color: transparent;
  border: none;
  box-shadow: none;
  outline: none;
}
li.container-custom {
  font-family: Raleway;
  margin: 0 auto;
  /*padding: 10em 3em;*/
  text-align: center;
}
li.container-custom button {
  color: #FFF;
  text-decoration: none;
  font: 20px Raleway;
  margin: 0px 10px;
  padding: 10px 10px;
  position: relative;
  z-index: 0;
  cursor: pointer;
}
/* Top and Bottom borders come in */
li.topBotomBordersIn button:before, li.topBotomBordersIn button:after {
  position: absolute;
  left: 0px;
  width: 100%;
  height: 2px;
  background: #FFF;
  content: "";
  opacity: 0;
  transition: all 0.3s;
  border: none; /* Added to override css added by class `.dropdown-toggle` */
  margin: 0; /* Added to override css added by class `.dropdown-toggle` */
}
li.topBotomBordersIn button:before {
  top: 0px;
  transform: translateY(-10px);
}
li.topBotomBordersIn button:after {
  bottom: 0px;
  transform: translateY(10px);
}
li.topBotomBordersIn button:hover:before, li.topBotomBordersIn button:hover:after {
  opacity: 1;
  transform: translateY(0px);
}
li.container-custom .dropdown-menu button.btn-custom-animated {
  color: #000;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>

<section class="container-fluid">
  <div class="col">
    <div class="row justify-content-md-center">
      <div class="col nav-color card-border">
        <ul class="nav nav-pills">
          <li class="container-custom topBotomBordersIn dropdown">
            <button class="btn-custom-animated dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">nav1dropdown</button>
            <div class="dropdown-menu">
              <button class="btn-custom-animated">dropdown1</button> 
              <button class="btn-custom-animated">dropdown2</button> 
              <button class="btn-custom-animated">dropdown3</button> 
            </div>                
          </li>
          <li class="container-custom topBotomBordersIn">
            <button class="btn-custom-animated">nav2</button> 
            <button class="btn-custom-animated">nav3</button> 
          </li>
        </ul>
      </div>
    </div>
  </div>
</section>

<script type="text/javascript">
  $('.dropdown-toggle').dropdown();
</script>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...