javascript - Automatically resize HTML buttons based onscreen size? - Stack Overflow

I am making an android mobile app using HTML and JavaScript with CSS. The problem is, I sent it to my f

I am making an android mobile app using HTML and JavaScript with CSS. The problem is, I sent it to my friend to test, and the buttons are tiny on his screen. Using CSS, I changed the button size by changing text size in CSS. Is there a way that I could have the button size change automatically so that it is proportional to the screen size? If not, how would I make the buttons bigger for larger screens, and smaller for smaller screens?

Please note: I am only using HTML, JavaScript, and CSS. If you give me anything else, please mane it possible to copy and paste because I will not know how to incorporate it in my code.

I am making an android mobile app using HTML and JavaScript with CSS. The problem is, I sent it to my friend to test, and the buttons are tiny on his screen. Using CSS, I changed the button size by changing text size in CSS. Is there a way that I could have the button size change automatically so that it is proportional to the screen size? If not, how would I make the buttons bigger for larger screens, and smaller for smaller screens?

Please note: I am only using HTML, JavaScript, and CSS. If you give me anything else, please mane it possible to copy and paste because I will not know how to incorporate it in my code.

Share Improve this question asked Feb 9, 2015 at 4:18 FyrebendFyrebend 1332 gold badges2 silver badges9 bronze badges 1
  • refer to this link stackoverflow./questions/11777598/… – Arpit Srivastava Commented Feb 9, 2015 at 4:28
Add a ment  | 

3 Answers 3

Reset to default 2

It sounds like you want a 'responsive' design, use media-queries and 'breakpoints'.

The breakpoints will be the width for each device you want to support.

  • for an iphone 5 you would use '641px' as the max width.

  • you first define the standard class. Then deviate from that using the media queries with css like so

#button{
     width:100%;         // first define your class
    }

   @media (max-width: 640px) {
      #button {
         width:50%;
      }
    }

http://iosdesign.ivomynttinen.

It probably be done by adding this tag in header

<meta name="viewport" content="width=device-width" />

or/and setting width in percentage.

ex.

  <input type="text" style="width:30%" />

You need to use the meta tag for responsive:

<meta name="viewport" content="initial-scale=1, maximum-scale=1">

The HTML:

<input type="submit" name="" class="my_button"/>

The CSS:

input.my_button{
     width:50%;
     height:32px;
     display:table;
     margin:0 auto;
}
@media screen and (max-width:360px){
     input.my_button{
          width:100%;
     }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742419836a4440461.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信