简体   繁体   English

jQuery mobile:如何设置文本输入的背景颜色

[英]jQuery mobile: How to set background color of text input

I want the background of a text input field which I use in a popup panel to be transparent. 我想在弹出面板中使用的文本输入字段的背景是透明的。 Using 运用

 style="background: rgba(38,38,38,0.5);"

does work for a textarea, but not for the text input field: 适用于textarea,但不适用于文本输入字段:

截图

Thanks in advance! 提前致谢!

You should set background-color of the parent element .ui-input-text : 你应该设置父元素的背景颜色.ui-input-text

<div style="background: rgba(38,38,38,0.5);" class="ui-input-text ui-shadow-inset ui-corner-all ui-btn-shadow ui-body-a ui-mini">
    <input data-mini="true" id="selectedNode" type="text" readonly="true" value="1234" class="ui-input-text ui-body-a">
</div>

Since div.ui-input-text is auto generated by jQuery Mobile, you should add this rule to your stylesheet: 由于div.ui-input-text是由jQuery Mobile自动生成的,因此您应该将此规则添加到样式表中:

.ui-input-text {
    background-color: rgba(38, 38, 38, 0.5);
}

in your example setting the background color of the input element works correctly but as your setting it to half transparent rgba(38,38,38,0.5) you're getting different results as the parent tags of your textarea and input textfield have different background colors. 在您的示例设置中,输入元素的背景颜色正常工作,但是当您将其设置为半透明rgba(38,38,38,0.5)时,由于textarea和输入文本字段的父标记具有不同的背景,因此会得到不同的结果颜色。

Use solid colors in this case to get better performance and to exclude side-effects like this. 在这种情况下使用纯色可以获得更好的性能并排除这样的副作用。 Or just make sure both parent tags have the same background color. 或者只是确保两个父标签具有相同的背景颜色。

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

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