简体   繁体   English

jQuery Mobile Button中的文本居中垂直对齐?

[英]Vertical align text middle in jQuery Mobile Button?

I'm attempting to shrink the height of a jQuery Mobile Button for a better fit in a list view, but I cannot get the text to line up properly. 我试图缩小jQuery移动按钮的高度,以使其更适合列表视图,但是我无法使文本正确对齐。 Here's my implementation so far: 到目前为止,这是我的实现:

.listDelBtn .ui-btn-text {
    margin: -5px -15px -5px -15px;
}

<a class="listDelBtn" data-role="button" data-theme="b" style="float: right; width: 75px; line-height: 11px; margin-top: 6px; z-index: 12; padding: 0 0px 0 0px;">delete</a>

the styled margins do affect the width of the button to give it a shorter length, however, the top and bottom margin values have no affect, regardless of the values tried. 样式化的边距确实会影响按钮的宽度,以使其具有较短的长度,但是,无论尝试使用哪种值,顶部和底部边距值均不起作用。 I've also attempted various padding , height, and other values with no luck. 我也尝试过各种padding,height和其他值,但是没有运气。 Line height was also the only inline style that had any affect on height of the button, but the text within is misaligned. 行高也是唯一影响按钮高度的行内样式,但是其中的文本未对齐。 Attempting on versions 1.0b1+ of jQuery Mobile btw. 尝试使用jQuery Mobile btw 1.0b1 +版本。

Here's an image of the resulting button for reference: 这是结果按钮的图像供参考: 按键

You can give height to your button then give same line-height to it. 您可以为button height ,然后为它设置相同的line-height

For example 例如

.listDelBtn{
 height:30px;
 line-height:30px;
}

Check this example http://jsfiddle.net/EQash/ 检查此示例http://jsfiddle.net/EQash/

@Inator I think vertical align middle works only for the Table elements and not for other cases. @Inator我认为垂直对齐中间仅适用于Table元素,不适用于其他情况。

In that case in the class you apply to button: 在这种情况下,您可以在类中应用按钮:

Set: display: table-cell 设置:显示:表格单元

and vertical-align: middle 和垂直对齐:中间

and possibly create a outer element say div and set its display to table like display: table and vertical-align: middle 并可能创建一个外部元素(例如div),并将其显示设置为表,例如display:table和vertical-align:middle

Hope it might work 希望它能起作用

The Inline margin-top style takes precedence over the the styles defined in the CSS class. 内联边距顶部样式优先于CSS类中定义的样式。 That's why CSS defined values have no effect. 这就是CSS定义的值无效的原因。 Solution is to add 解决方法是添加

margin-top: -5px !important;

to your CSS if you want the negative top margin to take effect. 如果您想使负上边距生效,请选择CSS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM