下拉对齐下拉 - 切换右键

时间:2017-10-05 07:52:21

标签: html css bootstrap-4

如何正确对齐引导下拉列表中的下拉切换?这里是我的代码和jsfiddle,你可以看到指向下方的箭头除了文本之外,我想要它在右边。

https://jsfiddle.net/9a83n353/

<div class="dropdown">
    <button class="btn dropdown-toggle btn-block text-left" style="background-color: white; border-color:#dee4ed" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Active</button>
    <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
        <a class="dropdown-item">Active</a>
        <a class="dropdown-item">Inactive</a>
    </div>
</div>

3 个答案:

答案 0 :(得分:3)

使用CSS旋转箭头:

.dropdown-toggle::after {
    -ms-transform: rotate(-90deg); /* IE 9 */
    -webkit-transform: rotate(-90deg); /* Chrome, Safari, Opera */
    transform: rotate(-90deg);
}

将CSS float添加到右对齐:

float:right;

答案 1 :(得分:2)

右对齐菜单切换

您可以在按钮上使用flexbox属性:

.is-flex {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

fiddle

右对齐菜单

将课程dropdown-menu-right添加到菜单中,如文档中所述:

https://v4-alpha.getbootstrap.com/components/dropdowns/#menu-alignment

fiddle

答案 2 :(得分:2)

你可以直接向.dropdown-toggle :: after添加一个浮点数。它看起来像这样:

.dropdown-toggle::after {
    display: inline-block;
    width: 0;
    height: 0;
    margin-left: .3em;
    vertical-align: middle;
    content: "";
    border-top: .3em solid;
    border-right: .3em solid transparent;
    border-left: .3em solid transparent;
    float: right;
    margin-top: 8px;
}