当前位置: 首页 > 知识库问答 >
问题:

引导Navbar[复制]

饶谦
2023-03-14

我正试图将导航栏的内容居中,但由于某种原因文本对齐:居中不起作用。这是我的HTML:

<body id="page-top" data-spy="scroll" data-target=".navbar-fixed-top">
  <!-- NAVBAR -->
  <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
    <div class="container">
      <div class="navbar-header page-scroll">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar_clps">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
      </div>
      <div class="collapse main-nav navbar-collapse" id="navbar_clps">
        <ul class="nav navbar-nav">
          <!--<li class="hidden"><a class="page-scroll" href="#page-top"></a></li>-->
          <li><a class="page-scroll color_animation" href="#about">About</a></li>
          <li><a class="page-scroll color_animation" href="#services">Services</a></li>
          <li><a class="page-scroll color_animation" href="#reservation">Reservation</a></li>
          <li><a class="page-scroll color_animation" href="#contact">Contact us</a></li>
          <li><a id="login_lnk" class="page-scroll color_animation" href="#login" data-toggle="modal">Login</a></li>
        </ul>
      </div>
      <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
  </nav>
</body>

这里是CSS:

.main-nav a {
  font-size: 20px;
  font-weight: 700;
  text-decoration: none;
  color: #000;
  display: block;
  text-align: center;
  padding: 2px 0;
  transition: color 0.3s ease-in-out;
}

.main-nav {
  text-align: center !important;
  /*margin:  auto 0 auto;*/
}

li {
  color: white !important;
  word-spacing: 5px !important;
}

我知道这个问题已经被问过了,我甚至看了一些问题,但他们没有帮助我(正如我所说,文本对齐不工作,它不是一个重复,因为解决方案文本对齐)。


共有3个答案

戚奇略
2023-03-14

添加这个CSS

.navbar-nav {
  float: none !important;
  margin: 0px auto !important;
  width: 437px !important;
}
姜森
2023-03-14

您可以使用CSS Flexbox。比如:

/* Use media query to only show it on tablets & desktops (to prevent menu from breaking on mobiles) */
@media screen and (min-width: 768px) {
  #navbar_clps {
    display: flex !important;
    justify-content: center;
  }
}

看看下面的片段(使用全屏):

css lang-css prettyprint-override">.main-nav a {
  font-size: 20px;
  font-weight: 700;
  text-decoration: none;
  color: #000;
  display: block;
  text-align: center;
  padding: 2px 0;
  transition: color 0.3s ease-in-out;
}

.main-nav {
  text-align: center !important;
  /*margin:  auto 0 auto;*/
}

li {
  color: white !important;
  word-spacing: 5px !important;
}

@media screen and (min-width: 768px) {
  #navbar_clps {
    display: flex !important;
    justify-content: center;
  }
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<body id="page-top" data-spy="scroll" data-target=".navbar-fixed-top">
    <!-- NAVBAR -->
    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <div class="container">
            <div class="navbar-header page-scroll">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar_clps">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
            </div>

            <div class="collapse main-nav navbar-collapse" id="navbar_clps">
                <ul class="nav navbar-nav">
<!--                    <li class="hidden"><a class="page-scroll" href="#page-top"></a></li>-->
                    <li><a class="page-scroll color_animation" href="#about">About</a></li>
                    <li><a class="page-scroll color_animation" href="#services">Services</a></li>
                    <li><a class="page-scroll color_animation" href="#reservation">Reservation</a></li>
                    <li><a class="page-scroll color_animation" href="#contact">Contact us</a></li>
                    <li><a id="login_lnk"class="page-scroll color_animation" href="#login" data-toggle="modal" >Login</a></li>
                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container -->
    </nav>
</body>
司空俊雅
2023-03-14

. navbar向左浮动,只需将其设置为浮动:无;显示:内联-块;最后使容器文本对齐:中心;

.main-nav a {
        font-size: 20px;
        font-weight: 700;
        text-decoration: none;
        color: #000;
        display: block;
        text-align: center;
        padding: 2px 0;
        transition: color 0.3s ease-in-out;
}

 .nav-center{
   display: inline-block;
   float: none !important;
 } 

    li{
    color: white !important;
    word-spacing: 5px !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <div class="container">
            <div class="navbar-header page-scroll">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar_clps">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
            </div>

            <div class="collapse main-nav navbar-collapse text-center navbar_clps">
                <ul class="nav navbar-nav nav-center">
<!--                    <li class="hidden"><a class="page-scroll" href="#page-top"></a></li>-->
                    <li><a class="page-scroll color_animation" href="#about">About</a></li>
                    <li><a class="page-scroll color_animation" href="#services">Services</a></li>
                    <li><a class="page-scroll color_animation" href="#reservation">Reservation</a></li>
                    <li><a class="page-scroll color_animation" href="#contact">Contact us</a></li>
                    <li><a id="login_lnk"class="page-scroll color_animation" href="#login" data-toggle="modal" >Login</a></li>
                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container -->
    </nav>
 类似资料:
  • 这是我的密码,我试过很多东西,欧比旺,帮帮我!我试着做了一个容器标签,对css的ro响应。

  • 本文向大家介绍引导程序navbar-static-top类,包括了引导程序navbar-static-top类的使用技巧和注意事项,需要的朋友参考一下 要创建随页面滚动的导航栏,请添加.navbar-static-top类。此类不需要将填充添加到<body>。 示例

  • 试着在bootstrap中做一个navbar。标题占用了所有空间,折叠div没有显示。而我从教程中输入了完全生成输出的精确代码。我做错了什么?这里是Bootstrap初学者。 我创建了一个带有navbar-hear和navbar-collable div的nav标记,其中有两个navbar选项列表 null null navbar-nav元素是不可见的,如果我移除caplable class,它们

  • 引入 import { createApp } from 'vue'; import { NavBar } from 'vant'; const app = createApp(); app.use(NavBar); 代码演示 基础用法 <van-nav-bar title="标题" left-text="返回" right-text="按钮" left-arrow @cl

  • 我得到了以下css规则 我希望有

  • 编译时出现问题:X ./src/App 中的错误.js 在“”中找不到导出“NavBar”(作为“NavBar”导入)/导航栏'(可能的导出:默认值)这是我的导航栏Js我已导出导航栏,但我仍收到此错误:) 这是App.js,我已经导出了应用程序,但它仍然显示错误