Bootstrap 4 alpha 6 nav-tabs右对齐项目

时间:2017-02-01 00:18:32

标签: bootstrap-4 twitter-bootstrap-4

我正在尝试创建一个菜单最右侧有nav-item dropdown的标签菜单。

Bootstrap 4 alpha 5,float-xs-right正常工作:http://codeply.com/go/FCFPpRqhZd

Bootstrap 4 alpha 6,我改为float-right,但它无效:http://codeply.com/go/5mddDUv1M6

有想法吗?

2 个答案:

答案 0 :(得分:6)

由于alpha 6现在是flexbox,float将不再适用于这种情况。

使用ml-auto实用程序类代替margin-left:auto

<div class="col-md-12">
    <ul class="nav nav-tabs">
        <li class="nav-item">
            <a href="#" class="nav-link active">Link 1</a>
        </li>
        <li class="nav-item">
            <a href="#" class="nav-link">Link 2</a>
        </li>
        <li class="nav-item">
            <a href="#" class="nav-link">Link 3</a>
        </li>
        <li class="nav-item">
            <a href="#" class="nav-link">Link 4</a>
        </li>
        <li class="nav-item dropdown ml-auto">
            <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Account</a>
            <div class="dropdown-menu">
                <a class="dropdown-item" href="#">Action</a>
                <a class="dropdown-item" href="#">Another action</a>
                <a class="dropdown-item" href="#">Something else here</a>
                <div class="dropdown-divider"></div>
                <a class="dropdown-item" href="#">Separated link</a>
            </div>
        </li>
    </ul>
</div>

http://www.codeply.com/go/hhV1aM49zz

答案 1 :(得分:0)

如果要在导航栏中将多个项目对齐到右侧,请参见以下示例:

<div class="container py-3">
    <div class="col-10 mx-auto">
        <ul class="nav nav-tabs small" role="tablist">
            <li class="nav-item"><a class="nav-link active" data-toggle="tab" href="#tab11" role="tab">First</a></li>
            <li class="nav-item ml-auto"><a class="nav-link" data-toggle="tab" href="#tab22" role="tab">More</a></li>
            <li class="nav-item"><a class="nav-link" data-toggle="tab" href="#tab33" role="tab">More 2</a></li>
        </ul>
        <div class="tab-content py-4">
            <div class="tab-pane active" id="tab11" role="tabpanel">
                <h2 class="mb-3">Right Align Individual Tabs</h2>
                <p>The above tabs use `ml-auto` to right align indiviual tabs</p>

            </div>
            <div class="tab-pane" id="tab22" role="tabpanel">
                <div class="card border-primary mb-3">
                    <div class="card-body">
                        <h3 class="card-title">Primary</h3>
                        <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
                        <a href="#" class="btn btn-outline-secondary">Outline</a>
                    </div>
                </div>
                <div class="card border-primary mb-3">
                    <div class="card-body">
                        <h3 class="card-title">Primary</h3>
                        <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
                        <a href="#" class="btn btn-outline-secondary">Outline</a>
                    </div>
                </div>
            </div>
            <div class="tab-pane" id="tab33" role="tabpanel">
                More..
            </div>
        </div>
    </div>
</div>

可以在这里找到一个小提琴示例:https://www.codeply.com/go/WtDULmFF9G/bootstrap-4-right-align-tabs

这里的技巧是在要对齐的第一个元素(从左到右)上设置ml-auto类。< / p>