html – 如何自动调整所有手机/平板电脑显示格式的尺寸?

前端之家收集整理的这篇文章主要介绍了html – 如何自动调整所有手机/平板电脑显示格式的尺寸?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我设计了一个页面,页面中有四个div标签.如果我在手机测试页面(5英寸),它完美匹配页面,如果我在平板电脑上测试同一页面,页面适合屏幕的30%.那么我如何设置div尺寸,以便适合所有类型的屏幕.

Fiddle link

HTML:

  1. <div class="bubble0" align="center">
  2. <h3>Three Levels </h3>
  3. </div>
  4. <div class="bubble" align="center"> </div><br/><br/>
  5. <div class="bubble1" align="center"> </div><br/><br/>
  6. <div class="bubble2" align="center"> </div><br/><br/>
  7. <button>Play</button>

任何建议请,

解决方法

这叫做 Responsive Web Development(RWD).
为了使页面响应所有设备,我们需要使用一些基本的基础,如:

1.将headport元标签设置在head中:

  1. <Meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0"/>

2.使用media queries.

例:-

  1. /* Smartphones (portrait and landscape) ----------- */
  2. @media only screen
  3. and (min-device-width : 320px)
  4. and (max-device-width : 480px) {
  5. /* Styles */
  6. }
  7.  
  8. /* Smartphones (landscape) ----------- */
  9. @media only screen
  10. and (min-width : 321px) {
  11. /* Styles */
  12. }
  13.  
  14. /* Smartphones (portrait) ----------- */
  15. @media only screen
  16. and (max-width : 320px) {
  17. /* Styles */
  18. }
  19.  
  20. /* iPads (portrait and landscape) ----------- */
  21. @media only screen
  22. and (min-device-width : 768px)
  23. and (max-device-width : 1024px) {
  24. /* Styles */
  25. }
  26.  
  27. /* iPads (landscape) ----------- */
  28. @media only screen
  29. and (min-device-width : 768px)
  30. and (max-device-width : 1024px)
  31. and (orientation : landscape) {
  32. /* Styles */
  33. }
  34.  
  35. /* iPads (portrait) ----------- */
  36. @media only screen
  37. and (min-device-width : 768px)
  38. and (max-device-width : 1024px)
  39. and (orientation : portrait) {
  40. /* Styles */
  41. }
  42.  
  43. /* Desktops and laptops ----------- */
  44. @media only screen
  45. and (min-width : 1224px) {
  46. /* Styles */
  47. }
  48.  
  49. /* Large screens ----------- */
  50. @media only screen
  51. and (min-width : 1824px) {
  52. /* Styles */
  53. }
  54.  
  55. /* iPhone 4 ----------- */
  56. @media
  57. only screen and (-webkit-min-device-pixel-ratio : 1.5),only screen and (min-device-pixel-ratio : 1.5) {
  58. /* Styles */
  59. }

或者我们可以直接使用RWD framework

> Bootstrap
> Foundation 3 etc.

一些好文章

Media Queries for Standard Devices – BY CHRIS COYIER

CSS Media Dimensions

更大的设备,中型设备&小型设备媒体查询. (在我的场景中工作)

以下媒体查询通用设备类型: – 较大的设备,中型设备&小型设备.
这只是基本的媒体类型,适用于所有的场景&容易处理代码而不是使用各种媒体查询只需要关心三种媒体类型.

  1. /*###Desktops,big landscape tablets and laptops(Large,Extra large)####*/
  2. @media screen and (min-width: 1024px){
  3. /*Style*/
  4. }
  5.  
  6. /*###Tablet(medium)###*/
  7. @media screen and (min-width : 768px) and (max-width : 1023px){
  8. /*Style*/
  9. }
  10.  
  11. /*### Smartphones (portrait and landscape)(small)### */
  12. @media screen and (min-width : 0px) and (max-width : 767px){
  13. /*Style*/
  14. }

猜你在找的HTML相关文章