Failing to align badges to right in drop
Trying to align badges to the right of each drop-down menu. Currently, the badges look like so:
with the associated code:
<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>
adding 'pull-right' to the badge class () causes the badges to collapse:
Also, using boostrap3, with the bootswatch cosmo template (in case that's relevant). Any ideas here?
You have missing closing >
on the SPAN tags, your class name uses ' not " and your data-target attribute has an invalid leading slash (at least these were what I discovered when I tested it). The only way I could get it to work was a combination of fixed width for the parent UL, along with right-floated ("pull-right") badge spans.
The following tested successfully in Firefox and Chrome under Twitter-Bootstrap 3:
<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>
You can do this with CSS3 flex boxes:
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;
}
Depending on you project you might want to check the browser compatibility.
Here is a good explanation of how it works.
尝试...(未测试)
<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/16914.html
上一篇: Visual Studio 2012性能分析未能加载符号文件
下一篇: 未能将徽章向右对齐