未能将徽章向右对齐
尝试将徽章对齐到每个下拉菜单的右侧。 目前,徽章如下所示:
与相关的代码:
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="dropdown ">
<a data-target="/business" href="/business" class="dropdown-toggle" data-toggle="dropdown">Business<b class="caret"></b></a>
<ul class="dropdown-menu">
<li >
<a href="/economy">Economy <span class='badge' today: 2</span></a>
</li>
<li >
<a href="/financials">Financial Reports <span class='badge' today: 78</span></a>
</li>
<li >
<a href="/interest">Interest Rates </a>
</li>
</ul>
</li>
</ul>
</div>
向徽章类()添加“向右拉”会导致徽章崩溃:
另外,使用boostrap3和bootswatch cosmo模板(以防相关)。 这里的任何想法?
您在SPAN标签上缺少关闭>
,您的类名称使用“not”,并且您的data-target属性具有无效的前导斜杠(至少这些是我在测试它时发现的)。唯一可以实现的方法是工作是父母UL的固定宽度以及右浮动(“右拉”)徽章跨度的组合。
以下在Twitter和Bootstrap 3下的Firefox和Chrome中成功测试:
<li class="dropdown ">
<a data-target="business" href="/business" class="dropdown-toggle" data-toggle="dropdown">Business<b class="caret"></b></a>
<ul class="dropdown-menu" style="width:250px;">
<li>
<a href="/economy"><span class="badge pull-right">today: 2</span>Economy</a>
</li>
<li>
<a href="/financials"><span class="badge pull-right">today: 78</span>Financial Reports</a>
</li>
<li>
<a href="/interest">Interest Rates </a>
</li>
</ul>
</li>
你可以使用CSS3弹性框来做到这一点:
的jsfiddle
HTML:
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
Dropdown <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li role="presentation">
<a role="menuitem" tabindex="-1" href="#">
<span>Something</span>
<span class="badge">0.5</span>
</a>
</li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="#">
<span>Something else</span>
<span class="badge">1</span>
</a>
</li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="#">
<span>Something seriously super super long</span>
<span class="badge">1 bajillion</span>
</a>
</li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="#">
<span>Something also quite long</span>
<span class="badge">½ bajillion</span>
</a>
</li>
</ul>
</div>
CSS:
.dropdown-menu a[role="menuitem"] {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
}
.dropdown-menu a[role="menuitem"] span:first-child {
-webkit-box-flex: 1;
-moz-box-flex: 1;
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
margin-right: 2em;
}
根据你的项目你可能想检查浏览器的兼容性。
这是一个很好的解释它是如何工作的。
尝试...(未测试)
<li >
<a href="/economy">
<span="pull-left">
Economy
</span>
<span class="pull-right">
<span class='badge' today: 2></span>
</span>
</a>
</li>
链接地址: http://www.djcxy.com/p/16913.html
上一篇: Failing to align badges to right in drop
下一篇: Cancelling MFMailComposeViewController causes a memory leak?