简体   繁体   English

使用jQuery更改jQuery Mobile“选择”的高度?

[英]Changing height of jQuery Mobile “select” with jQuery?

so this is a problem I'm having: 所以这是我遇到的一个问题:

在此处输入图片说明

I want to style the height of the select to that of my input. 我想将选择的高度设置为输入的高度。 The select uses the ui-btn-inner class which has padding, and when changed, the height of the select changes. 选择使用具有填充的ui-btn-inner类,并且当更改时,选择的高度也会更改。

Here's the padding created by ui-btn-inner : 这是ui-btn-inner创建的填充:

在此处输入图片说明

Here is my code: 这是我的代码:

    <div class="ui-grid-a">
        <div class="ui-block-a" style="width: 80%;">
            <div data-role="content" class="accountTransferLabels" style="padding-left: 0;">
            Amount:
            </div>

            <input type="text" autocomplete="off" class="translate" placeholder="0.0" data-clear-btn="true" autofocus required autocorrect="off" autocapitalize="off" data-theme="d"/>

        </div>
        <div class="ui-block-b" style="width: 20%; padding-left: 15px;">
            <div data-role="content" class="accountTransferLabels" style="padding-left: 0;">
            Amount:
            </div>

            <select name="select-choice-1" id="select-choice-1" data-theme="a" style="height: 40%; padding: 0; margin: 0;">
                    <option value="" style="padding: 0;">CAD</option>
                    <option value="" style="padding: 0;"></option>
            </select>

        </div>
    </div>

Notice wherever I put style="padding: 0;" 请注意,无论我在哪里放置style="padding: 0;" it still doesn't affect the padding? 它仍然不影响填充吗? jQuery Mobile generates code and I am unable to attach classes to that code. jQuery Mobile生成代码,但是我无法将类附加到该代码。

I'm a complete noob at jQuery and have no idea how to simply change the height of this select.. 我是jQuery的一个完全菜鸟,不知道如何简单地更改此选择的高度。

You are missing the obvious. 您缺少明显之处。

Your original select is not longer visible. 您原来的选择不再可见。 Also as you can see new one is just custom combination of <div>'s and <span>'s. 您还可以看到,新的只是<div>和<span>的自定义组合。 New custom select box will not inherit css from the old one. 新的自定义选择框将不会继承旧的CSS。 New select box CSS structure needs to be changed in order for this to work. 为了使其工作,需要更改新的选择框CSS结构。

Working example: http://jsfiddle.net/Gajotres/PMrDn/107/ 工作示例: http : //jsfiddle.net/Gajotres/PMrDn/107/

HTML: HTML:

<div class="ui-grid-a">
    <div class="ui-block-a" style="width: 80%;">
        <div data-role="content" class="accountTransferLabels" style="padding-left: 0;">
            Amount:
        </div>

        <input type="text" autocomplete="off" class="translate" placeholder="0.0" data-clear-btn="true" autofocus required autocorrect="off" autocapitalize="off" data-theme="d"/>

    </div>
    <div class="ui-block-b" style="width: 20%; padding-left: 15px;"  id="grid-container">
        <div data-role="content" class="accountTransferLabels" style="padding-left: 0;">
            Amount:
        </div>

        <select name="select-choice-1" id="select-choice-1" data-theme="a">
            <option value="" style="padding: 0;">CAD</option>
            <option value="" style="padding: 0;"></option>
        </select>

    </div>
</div>

CSS: CSS:

#grid-container .ui-select div span {
    padding-bottom: 0.14em  !important;
}

Or if you want for select box text to be perfectly centered take a look at this example: http://jsfiddle.net/Gajotres/PMrDn/108/ 或者,如果您想使选择框文本完美居中,请看以下示例: http : //jsfiddle.net/Gajotres/PMrDn/108/

CSS: CSS:

#grid-container .ui-select div span {
    padding-top: 0.2em  !important;
    padding-bottom: 0.2em  !important;
}

grid-container is just an id given to the grid container, so we can affect only this select box. grid-container只是提供给网格容器的ID,因此我们只能影响此选择框。 If we change .ui-select it will affect every single select box. 如果我们更改.ui-select,它将影响每个单独的选择框。

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

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