[英]Align caret with dotted bottom border in Bootstrap
I'd like to align a caret with a dotted bottom border. 我想将插入符号与虚线下边框对齐。
I managed to achieve it using this code but it works only in Chromium. 我设法使用此代码实现了它,但它仅在Chromium中有效。
HTML: HTML:
<h2 id="a11y-291">
More <div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle h2Title" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="dashedUnderline">albums</span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>
<a href="#" role="button">artists</a>
</li>
<li class="active">
<a href="#" role="button">albums</a>
</li>
</ul>
</div>
</h2>
and css: 和CSS:
.noMarginTop {
margin-top: 0;
}
.h2Title {
border: none;
font-size: 30px;
padding: 0;
line-height: 1em;
}
.h2Title:active,
.h2Title:hover,
.h2Title:focus {
background-color: transparent;
}
.caret {
display: inline-block;
margin-top: 1em; // Not aligned in FF
}
.h2Title .caret {
margin-left: 3px;
}
.dashedUnderline {
border-bottom: 1px dotted black;
}
.dropdown-menu {
left: 0;
right: 0;
min-width: 0;
}
It works as expected in Chromium: 它可以在Chromium中按预期工作:
But there is a slight offset in Firefox: 但是Firefox中有一点偏移:
Has anyone a more reliable way to achieve this? 有没有人更可靠的方法来实现这一目标? I cannot figure out what differs between Firefox and Chromium resulting in an offset.
我无法弄清Firefox和Chromium之间的区别是什么导致偏移。
Thanks 谢谢
.noMarginTop { margin-top: 0; } .h2Title { border: none; font-size: 30px; padding: 0; line-height: 1em; } .h2Title:active, .h2Title:hover, .h2Title:focus { background-color: transparent; } .h2Title .caret { margin-left: 3px; } /* you must add display:inline-block to.dashedUnderline and .caret */ .dashedUnderline, .caret { display:inline-block; float:left; } .caret { margin-top: 29px; } .dashedUnderline { border-bottom: 1px dotted black; } .dropdown-menu { left: 0; right: 0; min-width: 0; }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <script src="https://code.jquery.com/jquery-3.0.0.min.js" integrity="sha256-JmvOoLtYsmqlsWxa7mDSLMwa6dZ9rrIdtrrVYRnDRH0=" crossorigin="anonymous"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <div class="btn-group"> <h2 id="a11y-291"> More <button type="button" class="btn btn-default dropdown-toggle h2Title" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <span class="dashedUnderline">albums</span> <span class="caret"></span> </button> <ul class="dropdown-menu"> <li> <a href="#" role="button">artists</a> </li> <li class="active"> <a href="#" role="button">albums</a> </li> </ul> </h2> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.