集中导航栏上的按钮

时间:2016-09-16 17:55:47

标签: asp.net-mvc html5 css3 navbar

我的导航栏上有以下按钮:

<ul class="nav navbar-nav navbar-right" >

    <div class="btn-group ex" data-toggle="buttons" style="vertical-align:middle">
        <label class="btn btn-primary btn-sm">
            <input type="radio" name="options" id="blocos" value="blocos"> <span class="glyphicon glyphicon-th"></span>
        </label>
        <label class="btn btn-primary btn-sm">
            <input type="radio" name="options" id="lista" value="lista"> <span class="glyphicon glyphicon-align-justify"></span>
        </label>
    </div>
    <a class="btn btn-success btn-sm" id="infopopover" rel="popover" data-style="primary"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span></a>
    <input type="hidden" id="modoexibicao" />
    <input type="hidden" id="contratocod" />

    @Html.Partial("_LoginPartial")

</ul>

它们如下所示:

enter image description here

我希望他们在导航栏的中心保持对齐。怎么办?

2 个答案:

答案 0 :(得分:0)

在样式表中添加:

ul{
    text-align: center;
}

或添加&#39; text-align:center&#39;如果你不想要这种风格引用任何其他的ul,那么你可以在ul元素中使用其他适用的类。

答案 1 :(得分:0)

使用以下css代码:

.navbar-nav {
      height:50px; 
      display:flex; 
      align-items:center;
}

vertical-align:middle 在第二个div风格:

<ul class="nav navbar-nav navbar-right">

    <div class="btn-group ex" data-toggle="buttons" style="vertical-align:middle">
        <label class="btn btn-primary btn-sm">
            <input type="radio" name="options" id="blocos" value="blocos"> <span class="glyphicon glyphicon-th"></span>
        </label>
        <label class="btn btn-primary btn-sm">
            <input type="radio" name="options" id="lista" value="lista"> <span class="glyphicon glyphicon-align-justify"></span>
        </label>
    </div>
    <a class="btn btn-success btn-sm" id="infopopover" rel="popover" data-style="primary"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span></a>
    <input type="hidden" id="modoexibicao" />
    <input type="hidden" id="contratocod" />

    @Html.Partial("_LoginPartial")

</ul>