Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8271111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:45:46+00:00 2026-06-08T06:45:46+00:00

I have some html code and I load it to WebView. I need to

  • 0

I have some html code and I load it to WebView. I need to set button width in percents (in order to not to depend on the screen resolution).

When I set button’s width in percents I’m getting an error that page cannot be loaded butf I set it in pixels everything is okay.

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <style type='text/css'> 
            body{ position: relative; } 
            button { width: 50%; display: block; position: relative;  } 
        </style>
    </head>
    <body style='text-align:justify;color:white;'>
        Some text
        <br/>
        <button>Boo!</button>
    </body>
</html>

Any thoughts?

EDIT:

The solution was found based on @Zak’s advice, i.e., by calling the js function after the page was loaded, getting the screen width and setting it to the element.

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script language='javascript'> function SetWidth(){  d = document.getElementById('but'); d.style.width=screen.width/2; } </script>
    <style type='text/css'> body{ position: relative; } button { display: block; position: relative;  } </style>
    </head>

    <body style='text-align:justify;color:white;'>
        Text<br/>
        <button id='but' >Scary!</button>
        <script> window.onload=SetWidth; </script>
    </body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T06:45:47+00:00Added an answer on June 8, 2026 at 6:45 am

    I have done this with DIVs that I need to be exactly X percent of screen resolution. The way I accomplished this was using JQuery after the page has loaded, because JQuery can detect exact screen width, then you can do the math, and set a width to exactly X pixels.

    $(document).ready(function() {
     var = myWidth = screen.width;
    myWidth = myWidth / 2;
    $('#button').width(myWidth);
    });
    

    I havent checked that.. But the concept uis sound I assure you

    Also: Make sure this code is at the BOTTOM of the page to ensure it is rendered AFTER the page elements have loaded.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some HTML Code: <html> <head> <title>css test</title> <style type=text/css> .box{width:100%;float:left;background:red} </style> </head>
I have a load of text files with some html code in them. EG:
I have inherited some HTML code and have been asked to align the two
I have some auto-generated HTML code. When I add a float:left; on the shared
I have some HTML errors in my output source code, coming from one of
I have a td-element which can contain some HTML code, e.g. &lt; . This
I have simple HTML code with some JavaScript. It looks like: <html> <head> <script
I have some PHP code that generates a calendar and then outputs html to
I have a chunk of HTML code (with some PHP vars echoed inside of
I have this html code: <div class=action> some_text <a class=delete_action name=q1>some</a> </div> <div class=action>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.