当屏幕变窄时,如何解释Bootstrap 4固定导航栏变得越来越高

问题描述 投票:0回答:1

所以我有一个使用Bootstrap 4的固定导航栏

<div class="navbar  navbar-expand-lg navbar-dark bg-dark container">
        <a href="http://jthink.net/index.jsp" class="navbar-brand">
            JThink
        </a>
...

在我的body标签中,我添加了填充以说明固定导航栏的大小

<body style="padding-top: 100px;">

但是当然如果屏幕尺寸对于导航栏(例如电话)而言不够宽,则导航栏会变得更高以适应链接。因此,100px不再足够大,以避免导航栏隐藏内容。

那我该怎么处理这个呢?

我正在处理的实际页面是http://www.jthink.net/

css responsive-design bootstrap-4
1个回答
1
投票

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>Bootstrap 101 Template</title>

    <!-- Bootstrap -->
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
    <div class="container-fluid fixed-top bg-dark">
    <div class="navbar  navbar-expand-lg navbar-dark bg-dark container text-center">

        <a href="http://jthink.net/index.jsp" class="navbar-brand">
            <img src="http://www.jthink.net/images/icon32.png" width="30" height="30" class="d-inline-block align-top" alt="">
            JThink
        </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">
            <a class="nav-item nav-link" href="http://blog.jthink.net">
                Blog
            </a>
            <a class="nav-item nav-link" href="http://jthink.net/jaikozforum">
                User Forum
            </a>
            <a class="nav-item nav-link" href="http://jthink.net/songkong">
                SongKong
            </a>
            <a class="nav-item nav-link" href="http://jthink.net/jaikoz">
                Jaikoz
            </a>
            <a class="nav-item nav-link" href="http://albunack.net" target="_blank">
                Albunack
            </a>
            <a class="nav-item nav-link" href="http://www.jthink.net/jaudiotagger/index.jsp">
               Jaudiotagger
            </a>
        </ul>
      </div>
    </div>
</div>

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script>
  </body>
</html>

希望这对你有所帮助。我的代码缩进不好,但它必须逐行缩进(我认为)如此凌乱的代码,但我希望可读。

导航栏成为一种下拉菜单(带有汉堡按钮)。

这一切的重点是:你很好地使用bootstrap的函数,imho。

祝你好运:)

© www.soinside.com 2019 - 2024. All rights reserved.