我已将右对齐(pull-right
)bootstrap glyphicons
添加到我的dropdown-menu
选项中。问题是最长的选项会在名称和glyphicon
之间产生换行符。我怎样才能在同一条线上制作它们?当我尝试没有pull-right
时,一切都完美无缺。
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a
href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
aria-haspopup="true"
aria-expanded="false">
menu
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
{foreach from=$item key=sub_title item=sub_item}
<li>
<a
href="{$sub_item.url}"
target="_blank">
{$sub_title}
<span class="glyphicon glyphicon-{$sub_item.icon} pull-right" aria-hidden="true"></span>
</a>
</li>
{/foreach}
</ul>
</li>
</ul>
答案 0 :(得分:1)
float: right;
的图标必须在文字前面。
@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');
.item-text {
margin-right: 20px;
}
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">menu<span class="caret"></span></a>
<ul class="dropdown-menu">
<li>
<a href="#URL" target="_blank">
<span class="glyphicon glyphicon-tag pull-right" aria-hidden="true"></span>
<span class="item-text">short short</span>
</a>
</li>
<li>
<a href="#URL" target="_blank">
<span class="glyphicon glyphicon-tag pull-right" aria-hidden="true"></span>
<span class="item-text">long long long long long long long long long long long long long</span>
</a>
</li>
<li>
<a href="#URL" target="_blank">
<span class="glyphicon glyphicon-tag pull-right" aria-hidden="true"></span>
<span class="item-text">short short</span>
</a>
</li>
<li>
<a href="#URL" target="_blank">
<span class="glyphicon glyphicon-tag pull-right" aria-hidden="true"></span>
<span class="item-text">short short</span>
</a>
</li>
<li>
<a href="#URL" target="_blank">
<span class="glyphicon glyphicon-tag pull-right" aria-hidden="true"></span>
<span class="item-text">long long long long long long long long long long long long long</span>
</a>
</li>
<li>
<a href="#URL" target="_blank">
<span class="glyphicon glyphicon-tag pull-right" aria-hidden="true"></span>
<span class="item-text">long long long long long long long long long long long long long</span>
</a>
</li>
</ul>
</li>
</ul>
</div>
<div class="alert alert-danger visible-xs text-center">
Menu becomes visible in the window with a width of 768px or more.
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>