gpt4 book ai didi

css - 中心导航栏链接,而不是
  • 文本
  • 转载 作者:太空宇宙 更新时间:2023-11-04 11:42:31 25 4
    gpt4 key购买 nike

    我有这个 bootstrap 导航栏,它是我从 wrapbootstrap 购买的模板的一部分。我可以制作 <li>文本中心,但这不是我需要的。我需要能够在调整页面大小时 (@media 768px) 使导航栏元素居中,但无法弄清楚。

    这是我的导航栏:

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

    <!-- Toggle get grouped for better mobile display -->
    <div class="navbar-header">
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-1">
    <span class="sr-only">Toggle navigation</span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    </button>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="navbar-collapse-1">
    <ul class="nav navbar-nav navbar-right">
    <li class="active">@Html.ActionLink("Home", "Index", "Home", new { area = "" }, new { })</li>
    <li class="dropdown">
    <a data-toggle="dropdown" class="dropdown-toggle" href="#">Games</a>
    <ul role="menu" class="dropdown-menu">
    <li>@Html.ActionLink("Results", "Index", "Results", new { area = "" }, new { })</li>
    <li>@Html.ActionLink("League Table", "Index", "LeagueTable", new { area = "" }, new { })</li>
    </ul>
    </li>
    <li>@Html.ActionLink("Schedule", "Index", "Schedule", new { area = "" }, new { })</li>
    <li>@Html.ActionLink("Players", "Index", "Players", new { area = "" }, new { })</li>
    <li>@Html.ActionLink("News", "Index", "News", new { area = "" }, new { })</li>
    <li>@Html.ActionLink("Gallery", "Index", "Gallery", new { area = "" }, new { })</li>
    <li>@Html.ActionLink("Contact", "Contact", "Home", new { area = "" }, new { })</li>
    @if (Request.IsAuthenticated)
    {
    <li class="dropdown">
    <a data-toggle="dropdown" class="dropdown-toggle" href="#">Admin</a>
    <ul role="menu" class="dropdown-menu">
    <li>@Html.ActionLink("Admin", "Index", "Home", new { area = "Admin" }, new { })</li>
    <li>@Html.ActionLink("Games", "Index", "Games", new { area = "Admin" }, new { })</li>
    <li>@Html.ActionLink("Game Types", "Index", "GameTypes", new { area = "Admin" }, new { })</li>
    <li>@Html.ActionLink("News", "Index", "News", new { area = "Admin" }, new { })</li>
    <li>@Html.ActionLink("Players", "Index", "Players", new { area = "Admin" }, new { })</li>
    <li>@Html.ActionLink("Seasons", "Index", "Seasons", new { area = "Admin" }, new { })</li>
    </ul>
    </li>
    }
    </ul>
    </div>
    </div>
    </nav>

    现在,如果将页面大小调整为 768 像素,我的管理导航栏元素会下降到左侧,我希望它集中。

    谢谢。

    编辑:呈现的 HTML:

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

    <!-- Toggle get grouped for better mobile display -->
    <div class="navbar-header">
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-1">
    <span class="sr-only">Toggle navigation</span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    </button>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="navbar-collapse-1">
    <ul class="nav navbar-nav navbar-right">
    <li class="active"><a href="/">Home</a></li>
    <li class="dropdown">
    <a data-toggle="dropdown" class="dropdown-toggle" href="#">Games</a>
    <ul role="menu" class="dropdown-menu">
    <li><a href="/Results">Results</a></li>
    <li><a href="/LeagueTable">League Table</a></li>
    </ul>
    </li>
    <li><a href="/Schedule">Schedule</a></li>
    <li><a href="/Players">Players</a></li>
    <li><a href="/News">News</a></li>
    <li><a href="/Gallery">Gallery</a></li>
    <li><a href="/Home/Contact">Contact</a></li>
    <li class="dropdown">
    <a data-toggle="dropdown" class="dropdown-toggle" href="#">Admin</a>
    <ul role="menu" class="dropdown-menu">
    <li><a href="/Admin/Home">Admin</a></li>
    <li><a href="/Admin/Games">Games</a></li>
    <li><a href="/Admin/GameTypes">Game Types</a></li>
    <li><a href="/Admin/News">News</a></li>
    <li><a href="/Admin/Players">Players</a></li>
    <li><a href="/Admin/Seasons">Seasons</a></li>
    </ul>
    </li>
    </ul>
    </div>
    </div>
    </nav>
    <!-- navbar end -->

    最佳答案

    在媒体查询中定位导航栏内的链接(最大宽度:768px)

    输出:

    Centered Navbar

    @media (max-width: 768px) {
    .navbar-default .navbar-nav > li > a {
    text-align: center;
    }
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>

    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
    <nav class="navbar navbar-default" role="navigation">
    <div class="container-fluid">

    <!-- Toggle get grouped for better mobile display -->
    <div class="navbar-header">
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-1">
    <span class="sr-only">Toggle navigation</span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    </button>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="navbar-collapse-1">
    <ul class="nav navbar-nav navbar-right">
    <li class="active"><a href="/">Home</a>
    </li>
    <li class="dropdown">
    <a data-toggle="dropdown" class="dropdown-toggle" href="#">Games</a>
    <ul role="menu" class="dropdown-menu">
    <li><a href="/Results">Results</a>
    </li>
    <li><a href="/LeagueTable">League Table</a>
    </li>
    </ul>
    </li>
    <li><a href="/Schedule">Schedule</a>
    </li>
    <li><a href="/Players">Players</a>
    </li>
    <li><a href="/News">News</a>
    </li>
    <li><a href="/Gallery">Gallery</a>
    </li>
    <li><a href="/Home/Contact">Contact</a>
    </li>
    <li class="dropdown">
    <a data-toggle="dropdown" class="dropdown-toggle" href="#">Admin</a>
    <ul role="menu" class="dropdown-menu">
    <li><a href="/Admin/Home">Admin</a>
    </li>
    <li><a href="/Admin/Games">Games</a>
    </li>
    <li><a href="/Admin/GameTypes">Game Types</a>
    </li>
    <li><a href="/Admin/News">News</a>
    </li>
    <li><a href="/Admin/Players">Players</a>
    </li>
    <li><a href="/Admin/Seasons">Seasons</a>
    </li>
    </ul>
    </li>
    </ul>
    </div>
    </div>
    </nav>

    关于css - 中心导航栏链接,而不是 <li> 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31218611/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com