flebox пробел в колонке? - PullRequest
0 голосов
/ 13 ноября 2018

Здравствуйте, я пытаюсь заставить элементы навигации гамбургера выравниваться равномерно по всей 100vh области, я пробовал использовать пробел, но это не сработало.Это потому, что я использовал VH вместо px в качестве моей меры?Должен ли я использовать Aling-контент вместо этого?Было бы здорово, если бы кто-то мог объяснить, как работает flexbox justify-content.Спасибо!

* {
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.mobile {
  position: fixed;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  visibility: hidden;
  background: rgba(255, 255, 255, 0);
  width: 100vw;
  height: 100vh;
  z-index: 1;
  transition: visibility 1s, background 1s;
  transition-delay: .5s;
  font-family: "Georgia";
}

.mobile a {
  text-decoration: none;
  color: black;
}

.mobilenav {
  visibility: hidden;
  list-style: none;
  opacity: 0;
  transition: visibility .5s, opacity .5s;
}

.mobilenav.active {
  visibility: visible;
  opacity: 1;
  transition: visibility .5s, opacity .5s;
  transition-delay: .5s;
}

.hamburger {
  align-items: center;
  display: flex;
  width: 25px;
  height: 15px;
  margin-right: 50px;
  cursor: pointer;
  display: none;
  z-index: 2;
}

.hamburger.active .line {
  background: rgba(0, 0, 0, 0);
  transition: .2s;
}

.hamburger.active .line::before {
  transform: rotate(45deg);
  top: 0;
  transition: .5s;
}

.hamburger.active .line::after {
  transform: rotate(135deg);
  top: 0;
  transition: .5s;
}

.line {
  position: relative;
  background-color: black;
  width: 100%;
  height: 1px;
  transition: .5s;
}

.line::before,
.line::after {
  position: absolute;
  content: "";
  height: 1px;
  width: 100%;
  background-color: black;
}

.line::after {
  top: 6px;
  transition: .5s;
}

.line::before {
  top: -6px;
  transition: .5s;
}

.nav {
  justify-content: flex-end;
  display: flex;
  flex-wrap: wrap;
  letter-spacing: 1px;
  padding: 30px 0;
  margin-right: 50px;
}

.nav li {
  text-align: center;
  font-family: "Georgia";
  padding-left: 60px;
  font-size: .8em;
  font-weight: normal;
  letter-spacing: 1px;
  list-style: none;
}

.nav li a {
  position: relative;
  text-decoration: none;
  color: inherit;
  transition: color .5s;
}

.nav li a::before {
  top: 2em;
  content: "";
  position: absolute;
  width: 100%;
  height: 1px;
  bottom: 0;
  left: 0;
  background-color: black;
  -webkit-transform: scaleX(0);
  transform: scaleX(0);
  -webkit-transition: all 0.2s;
  transition: all 0.2s;
}

.nav li a:hover::before {
  -webkit-transform: scaleX(1);
  transform: scaleX(1);
 }

.nav, nav {
  align-items: center;
  display: flex;
}

nav .logo {
  margin-left: 50px;
  display: flex;
  justify-content: flex-start;
  flex: 1;
  font-family: Georgia, serif;
  font-size: .8em;
  padding: 30px 0;
  font-weight: bold;
  letter-spacing: 3px;
}

.sublogo {
  font-weight: lighter;
  margin-left: 10px;
}

.sublogo::before {
  content: '|';
  margin-right: 10px;
}


@media (max-width: 1120px) {
  .nav {
    display: none;
  }
  .hamburger {
    display: flex;
    -ms-transform: scale(1.2, 1.2);
    -webkit-transform: scale(1.2, 1.2);
    transform: scale(1.2, 1.2);
  }
  nav .logo {
    font-size: 1em;
    letter-spacing: 3px;
    transition: visibility .5s, opacity .5s;
  }
  nav .logo .sublogo {
    letter-spacing: 3px;
  }
  .logo.active {
    visibility: hidden;
    opacity: 0;
    transition: visibility .5s, opacity .5s;
  }
  .mobile.active {
    display: flex;
    visibility: visible;
    background: rgba(255, 255, 255, 1);
    transition: background 1s;
  }
}

@media (max-width: 600px) {
  nav .logo {
    font-size: 1em;
    letter-spacing: 3px;
  }
  .sublogo {
    display: none;
  }
}

/*--END OF NAV--*/

.picture {
  width: 100%;
  height: 400px;
  background-image: url(img/slider.jpg);
  background-size: cover;
  background-position: top;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta name="viewport" content="width=device-width" />
    <link rel="stylesheet" href="stylesheet.css">
    <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
    <script type="text/javascript">
      $(document).ready(function(){
        $('.hamburger').click(function(){
          $('.hamburger').toggleClass('active');
          $('.logo').toggleClass('active');
          $('.mobile').toggleClass('active');
          $('.mobilenav').toggleClass('active');
        })
      })
    </script>
    <meta charset="utf-8">
    <title>CSS & HTML NAVIGATION</title>
  </head>
  <body>
    <nav>
      <div class="logo">
        navigation.
        <div class="sublogo">
          this is my first example
        </div>
      </div>
      <ul class="nav">
        <li><a href="#">html</a></li>
        <li><a href="#">css</a></li>
        <li><a href="#">javascript</a></li>
        <li><a href="#">python</a></li>
        <li><a href="#">c++</a></li>
        <li><a href="#">php</a></li>
      </ul>
      <div class="hamburger">
        <div class="line">
        </div>
      </div>
      <div class="mobile">
        <ul class="mobilenav">
          <li><a href="#">html</a></li>
          <li><a href="#">css</a></li>
          <li><a href="#">javascript</a></li>
          <li><a href="#">python</a></li>
          <li><a href="#">c++</a></li>
          <li><a href="#">php</a></li>
        </ul>
      </div>
    </nav>
    <div class="picture">
      
    </div>
  </body>
</html>

1 Ответ

0 голосов
/ 13 ноября 2018

Вы должны установить высоту в классе mobilenav.Установите для элемента значение flex, а для его flex-direction: column и justify-content: space-evenly высота элемента блока по умолчанию равна высоте содержимого блока, поэтому для работы justify-content необходимо указать высоту.Надеюсь, это поможет.

* {
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.mobile {
  position: fixed;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  visibility: hidden;
  background: rgba(255, 255, 255, 0);
  width: 100vw;
  height: 100vh;
  z-index: 1;
  transition: visibility 1s, background 1s;
  transition-delay: .5s;
  font-family: "Georgia";
}

.mobile a {
  text-decoration: none;
  color: black;
}

.mobilenav {
  visibility: hidden;
  list-style: none;
  opacity: 0;
  transition: visibility .5s, opacity .5s;
  height: 100vh;
  justify-content: space-evenly;
  display: flex;
  flex-direction: column;
}

.mobilenav.active {
  visibility: visible;
  opacity: 1;
  transition: visibility .5s, opacity .5s;
  transition-delay: .5s;
}

.hamburger {
  align-items: center;
  display: flex;
  width: 25px;
  height: 15px;
  margin-right: 50px;
  cursor: pointer;
  display: none;
  z-index: 2;
}

.hamburger.active .line {
  background: rgba(0, 0, 0, 0);
  transition: .2s;
}

.hamburger.active .line::before {
  transform: rotate(45deg);
  top: 0;
  transition: .5s;
}

.hamburger.active .line::after {
  transform: rotate(135deg);
  top: 0;
  transition: .5s;
}

.line {
  position: relative;
  background-color: black;
  width: 100%;
  height: 1px;
  transition: .5s;
}

.line::before,
.line::after {
  position: absolute;
  content: "";
  height: 1px;
  width: 100%;
  background-color: black;
}

.line::after {
  top: 6px;
  transition: .5s;
}

.line::before {
  top: -6px;
  transition: .5s;
}

.nav {
  justify-content: flex-end;
  display: flex;
  flex-wrap: wrap;
  letter-spacing: 1px;
  padding: 30px 0;
  margin-right: 50px;
}

.nav li {
  text-align: center;
  font-family: "Georgia";
  padding-left: 60px;
  font-size: .8em;
  font-weight: normal;
  letter-spacing: 1px;
  list-style: none;
}

.nav li a {
  position: relative;
  text-decoration: none;
  color: inherit;
  transition: color .5s;
}

.nav li a::before {
  top: 2em;
  content: "";
  position: absolute;
  width: 100%;
  height: 1px;
  bottom: 0;
  left: 0;
  background-color: black;
  -webkit-transform: scaleX(0);
  transform: scaleX(0);
  -webkit-transition: all 0.2s;
  transition: all 0.2s;
}

.nav li a:hover::before {
  -webkit-transform: scaleX(1);
  transform: scaleX(1);
 }

.nav, nav {
  align-items: center;
  display: flex;
}

nav .logo {
  margin-left: 50px;
  display: flex;
  justify-content: flex-start;
  flex: 1;
  font-family: Georgia, serif;
  font-size: .8em;
  padding: 30px 0;
  font-weight: bold;
  letter-spacing: 3px;
}

.sublogo {
  font-weight: lighter;
  margin-left: 10px;
}

.sublogo::before {
  content: '|';
  margin-right: 10px;
}


@media (max-width: 1120px) {
  .nav {
    display: none;
  }
  .hamburger {
    display: flex;
    -ms-transform: scale(1.2, 1.2);
    -webkit-transform: scale(1.2, 1.2);
    transform: scale(1.2, 1.2);
  }
  nav .logo {
    font-size: 1em;
    letter-spacing: 3px;
    transition: visibility .5s, opacity .5s;
  }
  nav .logo .sublogo {
    letter-spacing: 3px;
  }
  .logo.active {
    visibility: hidden;
    opacity: 0;
    transition: visibility .5s, opacity .5s;
  }
  .mobile.active {
    display: flex;
    visibility: visible;
    background: rgba(255, 255, 255, 1);
    transition: background 1s;
  }
}

@media (max-width: 600px) {
  nav .logo {
    font-size: 1em;
    letter-spacing: 3px;
  }
  .sublogo {
    display: none;
  }
}

/*--END OF NAV--*/

.picture {
  width: 100%;
  height: 400px;
  background-image: url(img/slider.jpg);
  background-size: cover;
  background-position: top;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta name="viewport" content="width=device-width" />
    <link rel="stylesheet" href="stylesheet.css">
    <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
    <script type="text/javascript">
      $(document).ready(function(){
        $('.hamburger').click(function(){
          $('.hamburger').toggleClass('active');
          $('.logo').toggleClass('active');
          $('.mobile').toggleClass('active');
          $('.mobilenav').toggleClass('active');
        })
      })
    </script>
    <meta charset="utf-8">
    <title>CSS & HTML NAVIGATION</title>
  </head>
  <body>
    <nav>
      <div class="logo">
        navigation.
        <div class="sublogo">
          this is my first example
        </div>
      </div>
      <ul class="nav">
        <li><a href="#">html</a></li>
        <li><a href="#">css</a></li>
        <li><a href="#">javascript</a></li>
        <li><a href="#">python</a></li>
        <li><a href="#">c++</a></li>
        <li><a href="#">php</a></li>
      </ul>
      <div class="hamburger">
        <div class="line">
        </div>
      </div>
      <div class="mobile">
        <ul class="mobilenav">
          <li><a href="#">html</a></li>
          <li><a href="#">css</a></li>
          <li><a href="#">javascript</a></li>
          <li><a href="#">python</a></li>
          <li><a href="#">c++</a></li>
          <li><a href="#">php</a></li>
        </ul>
      </div>
    </nav>
    <div class="picture">
      
    </div>
  </body>
</html>
...