如何在按钮中拉一点文字

时间:2015-02-01 10:04:55

标签: html css

我有一个带图像和文字的简单按钮,但文字没有按图像对齐。

<button type="button" class="btn btn-danger btn-sm dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
    <img class="" style="min-width: 16px;min-height: 16px;width: 16px;height: 16px;" src="/Content/img/cart.png">
    <span>Buy</span> 
    <span class="caret"></span>
 </button>

截图

enter image description here

并且jsfiddle http://jsfiddle.net/e40sb9eg/

2 个答案:

答案 0 :(得分:0)

在您的文字范围内添加ID ...

<button type="button" class="btn btn-danger btn-sm dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
   <img class="" style="min-width: 16px;min-height: 16px;width: 16px;height: 16px;" src="/Content/img/cart.png">
   <span id="btn-text">Buy</span> 
   <span class="caret"></span>
</button>

在CSS中,添加

#btn-text {
    margin-top: 5px; /* Change this value if you want */
}

答案 1 :(得分:0)

您可以尝试将文字与图片与vertical-align属性对齐:

&#13;
&#13;
.btn > * {
    vertical-align: bottom;
}
&#13;
<button type="button" class="btn btn-danger btn-sm dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
    <img class="" style="min-width: 16px;min-height: 16px;width: 16px;height: 16px;" src="https://cdn3.iconfinder.com/data/icons/glypho-free/64/cart-alt-20.png">
    <span>Buy</span>
    <span class="caret"></span>
</button>
&#13;
&#13;
&#13;