【问题标题】:text-center and text-right not working in bootstraptext-center 和 text-right 在引导程序中不起作用
【发布时间】:2022-03-09 22:16:50
【问题描述】:

我希望页面上的一些元素居中和右对齐,但是引导类“text-right”和“text-center”似乎不起作用,即使“text-left”可以。

谢谢。

<div class="container-fluid">
    <div class="row text-center" id="header">
        <div class="col-xs-12">
            <div class="container" style="padding-left:30px; padding-right:30px;">
                <div class="col-xs-2 text-left" id="mainLogo">
                    <a href="/"><img src="/stylesheet/main_logo.png" ></a>
                </div>

                <div class="col-xs-6 text-right">
                    <ul class="nav nav-pills">
                        <li role="presentation" class="dropdown">
                            <a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-expanded="false">
                                <span class="glyphicon glyphicon-user"></span> Account <span class="caret"></span>
                            </a>
                            <ul class="dropdown-menu" role="menu">
                                <li id="ctl00">
                                    <a href="/account/">Your Account</a>
                                </li>
                                <li id="user">
                                    <a href="/profile/">Profile</a>
                                </li>
                                <li id="panel">
                                    <a href="/shop/reviewbasket/">Basket</a>
                                </li>
                            </ul>
                        </li>
                    </ul>
                </div>

                <div class="col-xs-4 text-right">
                    <div id="search">
                 </div>     
                </div>
                </div>
            </div>
        </div>
    </div>

【问题讨论】:

  • 您应该能够使用浏览器的开发人员控制台(“检查器”)查看正在应用的样式规则以及发生故障的位置。 text-righttext-center 确实有效,但可能不会达到如此高的水平。您可能需要将其放在导航栏中的每个 a
  • 我认为它正在工作,请参考这个小提琴jsfiddle.net/f0wL18zy你好在中心
  • 对于使用 Bootstrap 5 的未来读者,请参阅:stackoverflow.com/questions/18672452/…

标签: html css twitter-bootstrap twitter-bootstrap-3


【解决方案1】:

对于使用 Bootstrap 5 的用户,请注意 text-lefttext-right 类已被删除。现在您可以使用text-starttext-end

【讨论】:

  • 拯救了我的一天,谢谢
  • 我现在遇到的问题是 text-start 给了我右对齐,而 text-end 给了我左对齐。
  • @LiterateCorvette 请提出一个新问题并创建一个测试用例。
  • 你能提供文档的链接吗?我试图找到并仍然出现左右文本
  • 这应该是公认的答案
【解决方案2】:

引导程序 5 - 2022 年更新

作为explained hereleft & right 在 Bootstrap 5 中已替换为 start & end。 ..

  • 在块元素上使用float-end(即:div
  • 在内联元素上使用text-end(即:aspan

引导程序 4 - 2018 年更新

pull-right 已更改为 float-right

Bootstrap 3 - 原始答案

最初的问题是针对 Bootstrap 3 的,问题是 OP 试图在块元素上使用 text-right。 text-right 仅适用于内联元素。 UL 是一个块元素,因此您可以像这样使用pull-right..

<div class="col-xs-6">
     <ul class="nav nav-pills pull-right"> 
         ...

【讨论】:

    猜你喜欢
    • 2022-11-13
    • 2013-07-27
    • 1970-01-01
    • 1970-01-01
    • 2019-04-07
    • 2013-06-25
    • 1970-01-01
    • 1970-01-01
    • 2012-04-27
    相关资源
    最近更新 更多