【问题标题】:Background image position issue in android jelly Bean WebViewandroid jelly Bean WebView中的背景图像位置问题
【发布时间】:2026-02-24 14:00:02
【问题描述】:

背景图像位置在 Jelly Bean webView 中不呈现,但在 KitKat 版本中可以正常工作

CSS

    .clearable{
      background:url("../images/txtclear.png") no-repeat right 5px center !important;  
      border:1px solid #999;
      padding:3px 18px 3px 4px; 
      border-radius:3px; 
      transition: background 0.4s; 
    }

HTML

<html>
<body>
<input value="" id="txtsearch" type="email" placeholder="Enter Search string" class="clearable"/>
</body>
</html>

我还参考了以下 URL 中的类似帖子,但这不能解决我的问题。 background-attachment messes up rendering in Jelly Bean WebView?

【问题讨论】:

    标签: android html css webview


    【解决方案1】:

    background-position 仅在 Android 4.4 及更高版本中支持四值语法,这就是它无法正确呈现的原因。

    http://caniuse.com/#feat=css-background-offsets

    对于这些版本,您可以使用后备规则来正确显示。只需调整 % 或 px 以匹配您的项目宽度和高度。

    .clearable{
       background-position: 95% 50%; /* Will apply only for < 4.4 */
       background-position: right 5px center;
    }
    

    希望这会有所帮助!

    问候

    【讨论】: