日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Bootstrap 4:如何使顶部固定的Navbar保持在容器中而不拉伸?

發(fā)布時間:2023/11/29 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Bootstrap 4:如何使顶部固定的Navbar保持在容器中而不拉伸? 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

There are many ways to make a fixed navbar stay inside a parent's div container. We'll go over the most straightforward one here.

有很多方法可以使固定的導(dǎo)航欄停留在父級的div容器中。 我們將在這里介紹最簡單的方法。

Imagine you have the following code, modified slightly from the Bootstrap docs:

想象一下,您有以下代碼,是從Bootstrap文檔中稍作修改的:

<div class="container"><nav class="navbar navbar-fixed-top navbar-inverse bg-inverse"><button class="navbar-toggler hidden-lg-up" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation"></button><div class="collapse navbar-toggleable-md" id="navbarResponsive"><a class="navbar-brand" href="#"><img src="" width="30" height="30" class="d-inline-block align-top" alt="">Navbar</a><ul class="nav navbar-nav float-md-right"><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><li class="nav-item"><a class="nav-link" href="#">Link</a></li></ul></div></nav><div class="next"></div>hello </div>div.next {background-color: lightblue;width: 100%;height: 60rem; }

And your page looks like this:

您的頁面如下所示:

解決方案 (Solutions)

While the docs read "Navbars and their contents are fluid by default. Use optional containers to limit their horizontal width," the easiest solution is to use CSS to set the width of the navbar directly:

當(dāng)文檔閱讀“導(dǎo)航欄及其內(nèi)容默認(rèn)情況下是可變的。使用可選容器限制其水平寬度”時,最簡單的解決方案是使用CSS直接設(shè)置導(dǎo)航欄的寬度:

div.next {background-color: lightblue;width: 100%;height: 60rem; }.container {padding: 0px; }nav.navbar {width: inherit;top: 0%;left: 50%;transform: translateX(-50%); }

By adding rules targeting .container and nav.navbar, your navbar is now the same width as the parent's container:

通過添加針對.container和nav.navbar規(guī)則,您的導(dǎo)航欄現(xiàn)在與父容器的寬度相同:

翻譯自: https://www.freecodecamp.org/news/bootstrap-4-how-to-make-top-fixed-navbar-stay-in-container-and-not-stretch/

總結(jié)

以上是生活随笔為你收集整理的Bootstrap 4:如何使顶部固定的Navbar保持在容器中而不拉伸?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。