最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to make the page to fit screen width on mobile device? - Stack Overflow

programmeradmin3浏览0评论

I have the one form page. I need this form scaled and fit to screen width on any device (Android, iOS, ...). How can I do it with HTML or CSS? style="width:100%" is not a solution in my case.

Thanks!

I have the one form page. I need this form scaled and fit to screen width on any device (Android, iOS, ...). How can I do it with HTML or CSS? style="width:100%" is not a solution in my case.

Thanks!

Share Improve this question asked Sep 30, 2013 at 17:15 Dmytro ZarezenkoDmytro Zarezenko 10.7k12 gold badges66 silver badges105 bronze badges 1
  • Use media queries. Look up responsive design. – Josh Crozier Commented Sep 30, 2013 at 17:15
Add a ment  | 

1 Answer 1

Reset to default 4

Why is width:100% not an option?

You can use media queries to target different screen sizes like so:

form {
    width: 800px;
}

@media only screen and (max-width: 800px) {
    form {
        width: 100%;
    }
}

The above code would make form 800px wide on any screen wider than 800px, and if it is displayed on a screen size equal to or below 800px wide it will be 100% instead. You can use as many of these as you want, so for instance you could put another media query after this for max-width: 500px and change the form styles accordingly for screen sizes 500px and below.

发布评论

评论列表(0)

  1. 暂无评论