Bootstrap 4 -防止链接在导航栏上断线

oiopk7p5  于 2022-12-16  发布在  Bootstrap
关注(0)|答案(3)|浏览(143)

当我在导航栏中有太多的链接时,当我开始放大时,然后链接开始断线。我希望它们在折叠之前保持在同一行。
在下面的片段(查看全尺寸),有6个链接,当你放大,有一定的缩放,链接断开线(在导航栏崩溃之前)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-expand-lg navbar-light fixed-top">
    <div class="container">
        <a class="navbar-brand mx-auto" href="#">
			Logo
        </a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse text-right" id="navbarTogglerDemo02">         
            <ul class="navbar-nav ml-auto mt-2 mt-lg-0">
                <li class="nav-item main-nav">
                    <a class="nav-link" href="#">Navbar Link Number 1</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Navbar Link Number 2</a>
                </li>
                <li class="nav-item">
                    <a  class="nav-link" href="#">Navbar Link Number 3</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Navbar Link Number 4</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Navbar Link Number 5</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Navbar Link Number 6</a>
                </li>
           </ul>
        </div>
    </div>
</nav>
pgccezyw

pgccezyw1#

在链路上使用text-nowrap实用程序类...
https://www.codeply.com/go/tKwvJnDJ42

<nav class="navbar navbar-expand-lg navbar-light fixed-top">
    <div class="container">
        <a class="navbar-brand mx-auto" href="#">
            Logo
        </a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse text-right" id="navbarTogglerDemo02">         
            <ul class="navbar-nav ml-auto mt-2 mt-lg-0">
                <li class="nav-item main-nav">
                    <a class="nav-link text-nowrap" href="#">Navbar Link Number 1</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link text-nowrap" href="#">Navbar Link Number 2</a>
                </li>
                <li class="nav-item">
                    <a  class="nav-link text-nowrap" href="#">Navbar Link Number 3</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link text-nowrap" href="#">Navbar Link Number 4</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link text-nowrap" href="#">Navbar Link Number 5</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link text-nowrap" href="#">Navbar Link Number 6</a>
                </li>
           </ul>
        </div>
    </div>
</nav>
7kqas0il

7kqas0il2#

对于来自Google的任何人来说,不要使用另一个解决方案中提到的&nbsp;,它会使内容无法管理,并使用标记来指示表示。
您可以模仿Bootstrap对简单类所做的操作,例如;

.text-nowrap {
    white-space: nowrap !important;
}

因为它是一个实用程序类,所以可以使用!important
希望能有所帮助

u59ebvdq

u59ebvdq3#

你可以隐藏溢出的链接,如果放大的用户很少,比 Package 菜单2行:

<style>
   @media (min-width: 1201px) {
        .navbar-nav {
            overflow: hidden !important;
            max-height: 50px;
        }
   }
</style>

相关问题