Bootstrap 4垂直导航栏

时间:2017-03-14 14:58:17

标签: css bootstrap-4

我正在尝试创建一个在某个断点处折叠的垂直导航栏。我已经将它解决了崩溃的程度,但不知怎的,我在下一篇专栏文章中的内容没有得到正确的叠加。

<div class="row">
    <div class="col-xs-3 col-sm-2 col-md-2 col-lg-1 col-xl-1">
        <div class="container">
            <nav class="nav navbar-light navbar-toggleable-sm">
                <button class="navbar-toggler navbar-toggler-left" type="button" data-toggle="collapse" data-target="#navbarW" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="navbar-collapse collapse flex-column" id="navbarWEX">
                    <a class="navbar-brand active" href="~/Views/Forms/ControlPanel.cshtml"><span class="fa fa-home"></span></a>
                    @Html.ActionLink("Create User", "Register", "Account", new { @class = "nav-link" })

                </div>
            </nav>
        </div>
    </div>
    <div class="col-xs-9 col-sm-10 col-md-10 col-lg-11 col-xl-11">
        <h2>Hello There</h2>
        <p>Test test test test test test test </p>
    </div>
</div>

有人可以指出我在这里做错了吗?

更新:谢谢@Zimsystem。以下是我提出的建议:

<div class="row h-100">
    <div class="col-2 collapse d-md-flex pt-2 h-100" id="sidebar">
        <nav class="nav flex-column">
            <a class="navbar-link active" href="~/Forms/ControlPanel"><span class="fa fa-home fa-3x ml-3"></span></a>
            @Html.ActionLink("Create User", "Register", "Account", new { @class = "nav-link" })
            @Html.ActionLink("Manage Users", "ManageUsers", "Account", new { @class = "nav-link" })     
        </nav>
    </div>
    <div class="col pt-2" id="wLayout">
        <p>Test test test test test test test </p>
    </div>
</div>

1 个答案:

答案 0 :(得分:8)

导致问题的各种问题。在最新的Bootstrap 4(alpha 6)中,-xs-中缀已被删除,因此只有col-3col-9,这导致了叠加问题。此外,container不应在col-内使用。

<div class="container-fluid">
    <div class="row">
        <div class="col-3 col-sm-2 col-md-2 col-lg-1 col-xl-1">
            <nav class="nav navbar-light navbar-toggleable-sm">
                <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarWEX" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="navbar-collapse collapse flex-column mt-md-0 mt-4 pt-md-0 pt-4" id="navbarWEX">
                    <a class="nav-link navbar-brand active" href="~/Views/Forms/ControlPanel.cshtml"><span class="fa fa-home"></span></a>
                    <a href="" class="nav-link">Linnk</a>
                    <a href="" class="nav-link">Linnk</a>
                    <a href="" class="nav-link">Linnk</a>
                </div>
            </nav>
        </div>
        <div class="col-9 col-sm-10 col-md-10 col-lg-11 col-xl-11">
            <h2>Hello There</h2>
        </div>
    </div>
</div>

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

注意:navbar-toggleable-*已替换为Bootstrap 4 Beta 3(及更新版本)中的navbar-expand-*

另见:
Bootstrap 4: responsive sidebar menu to top navbar
How to use CSS position sticky to keep a sidebar visible with Bootstrap 4
Create a responsive navbar sidebar "drawer" in Bootstrap 4?