单击切换器时,引导导航元素被下推

时间:2020-05-01 07:17:28

标签: html css twitter-bootstrap layout navigation

我正在使用Bootstrap4。我的目标是使用切换器在左侧,中间的文本和右侧的文本进行导航。问题是,在单击切换器以显示导航后,它会按下导航元素。我注意到的是,在不更改order属性的情况下,它可以正常工作,并且不会压低元素,但是我尝试使用order属性来做到这一点,因为它看起来很干净。

body
{
  margin: 0;
  padding: 0;
}

/* Navigation Start */
.navbar-bg-custom
{
  background-color: red;
}

.navbar
{
  justify-content: space-between;
}

.navbar-brand
{
  order: 2;
}

.navbar-nav{

}

.icon
{
  order: 3;
}

.navbar-brand img
{
  height: 80px;
}
/* Navigation End */
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
  <link rel="stylesheet" href="css/style.css">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
</head>
<body>

  <nav class="navbar navbar-light navbar-bg-custom">
  <a class="navbar-brand" href="#">This is getting pushed down on </a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>
    </ul>
  </div>
  <div class="icon">
    This too
  </div>
</nav>

  <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

我在计算机上测试了您的代码,并且知道,至少当我删除外观样式时,navabar品牌就在其位置上。

我可以向您保证,如果避免在使用Bootstrap时使用CSS代码为html元素提供诸如margin,padding或position属性之类的尺寸属性,那么您将不会遇到此问题。

在大多数情况下,我建议您使用引导程序库的样式和尺寸属性。

您指定的尺寸会导致引导程序属性出现偏差

请告诉我这个答案是否有帮助。