CSS with ID selector is not loading on android Webview

I'm trying to load html with CSS which has ID selector and it seems not to be working. This is the file which I tried to load:

  <!DOCTYPE html>
   <html>
    <head>
    <style>
     #para1 {
           text-align: center;
           color: red;
           }
    </style>
 </head>
<body>
 <p id="para1">Hello World!</p>
 <p>This paragraph is not affected by the style.</p>
    </body>
 </html>

This doesn't work.However when I tried this code,it worked.

     <!DOCTYPE html>
     <html>
      <body style="background-color:powderblue;">
           <h1>This is a heading</h1>
            <p>This is a paragraph.</p>
          </body>
         </html>

I have enabled these properties on the WebView:

    mWebView.setWebViewClient(new CustomWebViewClient());
    mWebView.setWebChromeClient(new CustomWebChromeClient());
    mWebView.getSettings().setSupportZoom(true); // ZoomControls
    mWebView.getSettings().setBuiltInZoomControls(true); // Multitouch
    mWebView.getSettings().setDisplayZoomControls(false);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setDomStorageEnabled(true);
    mWebView.getSettings().setLoadWithOverviewMode(true);
    mWebView.getSettings().setUseWideViewPort(CONFIG.webviewEnableViewport());
    mWebView.getSettings().setAllowFileAccess(true);
    mWebView.requestFocus(View.FOCUS_DOWN);
    mWebView.setHorizontalScrollBarEnabled(true);
    mWebView.setVerticalScrollBarEnabled(true);

Can anyone help me on this?



Read more here: https://stackoverflow.com/questions/68476794/css-with-id-selector-is-not-loading-on-android-webview

Content Attribution

This content was originally published by anju jo at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: