Navbar%页面高度

时间:2017-09-21 04:29:34

标签: html css twitter-bootstrap navbar

我想要的只是我的Navbar是页面高度5%的百分比,最小值为128px这样我的徽标总是至少128px或更大。

问题在于,这只是填充页面并且似乎使用了徽标大小。

代码:



.navbar {
  background-color: #1b1b1b;
}

.navbar>.container-fluid
.navbar>.container-fluid>.navbar-header,
.navbar>.container-fluid>.navbar-header>.navbar-brand{
  height: inherit;
}

.navbar>.container-fluid {
  margin-left:  18%;
  margin-right: 18%;
  padding-left: 0;
  padding-right: 0;
}

.navbar-brand>img {
  height: 100%;
  width: auto;
}

.navbar-default .navbar-nav>li>a{
  color: white;
}

<!DOCTYPE html>
<html>
  <head>
    <title>OG Visuals</title>

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>

  </head>
  <body>
    
    <nav class="navbar navbar-default">
      <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
          <a class="navbar-brand" href="index.php"><img src="http://img.freepik.com/free-icon/telegram-logo_318-102687.jpg?size=338c&ext=jpg" alt="Logo" /></a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div id="bs-example-navbar-collapse-1">
          <ul class="nav navbar-nav navbar-right">
            <li><a href="about.php">About</a></li>
            <li><a href="contact.php">Contact</a></li>
          </ul>
        </div><!-- /.navbar-collapse -->
      </div><!-- /.container-fluid -->
    </nav>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:1)

height: 5vh; min-height: 128px;提供给navbar-header,将height: 100%提供给container-fluid,将height: inherit提交给navbar-headernavbar-brand

&#13;
&#13;
.navbar {
  background-color: #1b1b1b;
}

.navbar>.container-fluid>.navbar-header, .navbar>.container-fluid>.navbar-header>.navbar-brand{
  height: inherit;
 } 

.navbar>.container-fluid {
  margin-left:  18%;
  margin-right: 18%;
  padding-left: 0;
  padding-right: 0;
  height: 100%;
}

.navbar-brand>img {
  height: 100%;
  width: auto;
}

.navbar.navbar-default {
   height: 5vh;
   min-height: 128px; 
}

.navbar-default .navbar-nav>li>a{
  color: white;
}
&#13;
<!DOCTYPE html>
<html>
  <head>
    <title>OG Visuals</title>

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>

  </head>
  <body>
    
    <nav class="navbar navbar-default">
      <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
          <a class="navbar-brand" href="index.php"><img src="http://img.freepik.com/free-icon/telegram-logo_318-102687.jpg?size=338c&ext=jpg" alt="Logo" /></a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div id="bs-example-navbar-collapse-1">
          <ul class="nav navbar-nav navbar-right">
            <li><a href="about.php">About</a></li>
            <li><a href="contact.php">Contact</a></li>
          </ul>
        </div><!-- /.navbar-collapse -->
      </div><!-- /.container-fluid -->
    </nav>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

如果您检查元素(分别为div.navbar-brandimg),您首先会看到:.navbar-brand有height: inherit;这意味着它会继承。因此,解决此问题的方法之一是.navbar-brand height: 128px;