如何使标题和徽标响应?(Bootstrap)

时间:2018-02-12 13:40:04

标签: html css twitter-bootstrap

好的,我制作了标题和徽标:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Test</title>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <link rel="stylesheet" type="text/css" href="test2.css">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>


    <div class="navbar navbar-default " role="navigation">
     <div class="container-fluid">

      <div class="navbar-header">
        <button class="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
          <span class="sr-only">Toggle Navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="#"><img src="images/test1.png" class="img-fluid"></a>
      </div>

    <div class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
        <li><a href="#">HOME</a></li>
        <li><a href="#">LINK</a></li>
        <li><a href="#">LINK</a></li>
        <li><a href="#">LINK</a></li>
        <li><a href="#">LINK</a></li>
      </ul>
   </div>

 </div>
</div>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>

和CSS:

.navbar-nav {
min-height: 110px;
}

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

问题是如何在我调整浏览器大小以及如何响应标题(减小尺寸时)时,我的徽标图像是否响应?正如您所看到的,我将高度放在外部CSS文件110px中,现在我想在调整大小到小屏幕时将徽标输入内部标题(如在全尺寸浏览器中)。我希望你明白了

2 个答案:

答案 0 :(得分:1)

要始终将标题图片保留在标题内,您只需将"repository"应用于图片即可。这将阻止它溢出其容器。以下是一个示例: https://jsfiddle.net/rktr4q5v/1/

你可以看到图像都非常小。这是因为类navbar-brand的高度为50px。如果删除此图像,则图像将扩展到原始宽度,但仍保留在导航栏内。以下是此示例: https://jsfiddle.net/rktr4q5v/2/

如果您需要为徽标执行特定尺寸样式,则需要使用媒体查询以不同的屏幕宽度更改徽标的大小。可以找到here和初学者guide can be found here

的相关文档

答案 1 :(得分:1)

我还修正了你的一些错误。你可以参考这个。

在导航栏品牌样式标签中调整徽标大小。如果需要

&#13;
&#13;
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Test</title>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <link rel="stylesheet" type="text/css" href="test2.css">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="navbar navbar-default " role="navigation">
     <div class="container-fluid">

      <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
          <span class="sr-only">Toggle Navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="#"><img src="https://static.pexels.com/photos/34950/pexels-photo.jpg" class="img-responsive img-rounded" style="max-height: 40px; margin-top: -15%;"></a>
      </div>

    <div class="navbar-collapse collapse navbar-right">
      <ul class="nav navbar-nav">
        <li><a href="#">HOME</a></li>
        <li><a href="#">LINK</a></li>
        <li><a href="#">LINK</a></li>
        <li><a href="#">LINK</a></li>
        <li><a href="#">LINK</a></li>
      </ul>
   </div>
   </div>
</div>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>
&#13;
&#13;
&#13;