具有全屏覆盖的bootstrap4导航栏

时间:2017-11-25 17:02:45

标签: html5 twitter-bootstrap

我希望bootstrap 4导航栏保持完全展开状态。此外,我想有一个叠加元素,图像和文本在右边对齐。即可点击的img / text"所有类别",都与右边对齐。

这就是我所拥有的。我无法让文字向右移动。



.overlay {
    height: 100%;
    width: 0;
    position: fixed;
    z-index: 1;
    top: 0;
    left: 0;
    background-color: rgb(0,0,0);
    background-color: rgba(0,0,0, 0.9);
    overflow-x: hidden;
    transition: 0.5s;
}

.overlay-content {
    position: relative;
    top: 25%;
    width: 100%;
    text-align: center;
    margin-top: 30px;
}

.overlay a {
    padding: 8px;
    text-decoration: none;
    font-size: 36px;
    color: #818181;
    display: block;
    transition: 0.3s;
}

.overlay a:hover, .overlay a:focus {
    color: #f1f1f1;
}

.overlay .closebtn {
    position: absolute;
    top: 20px;
    right: 45px;
    font-size: 60px;
}

<body>
  
  <div id="myNav" class="overlay">
  <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
  <div class="overlay-content">
    <a href="#">About</a>
    <a href="#">Services</a>
    <a href="#">Clients</a>
    <a href="#">Contact</a>
  </div>
</div>
  
  
  <nav class="navbar navbar-expand navbar-light bg-light">
    <a class="navbar-brand" href="#">
      <img src="img/icons/logo/pquizlogo.svg" width="38" height="38" class="d-inline-block align-top" alt="">Brand-name
    </a>
    <div>
    <span style="font-size:30px;cursor:pointer" onclick="openNav()">&#9776; All categories</span>
      <script>
      function openNav() {
      document.getElementById("myNav").style.width = "100%";
      }
      function closeNav() {
      document.getElementById("myNav").style.width = "0%";
      }
      </script>
    </div>
  </nav>
</body>
&#13;
&#13;
&#13;

请告诉我HTML是否正常,以及如何制作&#39;所有类别&#39;显示在导航栏的右侧。

谢谢!

1 个答案:

答案 0 :(得分:0)

您需要将span元素设置为display:block;,然后才能使用text-align: right;

我在跨度中添加了一个类nav-icon,并将您的内联样式移到了css部分:

.overlay {
    height: 100%;
    width: 0;
    position: fixed;
    z-index: 1;
    top: 0;
    left: 0;
    background-color: rgb(0,0,0);
    background-color: rgba(0,0,0, 0.9);
    overflow-x: hidden;
    transition: 0.5s;
}

.overlay-content {
    position: relative;
    top: 25%;
    width: 100%;
    text-align: center;
    margin-top: 30px;
}

.overlay a {
    padding: 8px;
    text-decoration: none;
    font-size: 36px;
    color: #818181;
    display: block;
    transition: 0.3s;
}

.overlay a:hover, .overlay a:focus {
    color: #f1f1f1;
}

.overlay .closebtn {
    position: absolute;
    top: 20px;
    right: 45px;
    font-size: 60px;
}

.nav-icon{
     font-size:30px;
     cursor:pointer;
     display: block;
     text-align: right;
}
<body>
  
  <div id="myNav" class="overlay">
  <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
  <div class="overlay-content">
    <a href="#">About</a>
    <a href="#">Services</a>
    <a href="#">Clients</a>
    <a href="#">Contact</a>
  </div>
</div>
  
  
  <nav class="navbar navbar-expand navbar-light bg-light">
    <a class="navbar-brand" href="#">
      <img src="img/icons/logo/pquizlogo.svg" width="38" height="38" class="d-inline-block align-top" alt="">Brand-name
    </a>
    <div>
    <span class="nav-icon" onclick="openNav()">All categories &#9776;</span>
      <script>
      function openNav() {
      document.getElementById("myNav").style.width = "100%";
      }
      function closeNav() {
      document.getElementById("myNav").style.width = "0%";
      }
      </script>
    </div>
  </nav>
</body>