简体   繁体   English

如何调整内容以自动适合屏幕尺寸?

[英]How to adjust contents to automatically fit size of the screen?

I have an requirement that an application(HTML, CSS and Javascript) should adjust automatically to screen window size - from laptops, to desktops to tablets. 我要求应用程序(HTML,CSS和Javascript)应自动调整以适应屏幕窗口的大小-从笔记本电脑到台式机再到平板电脑。 Does anyone know how can this be done? 有谁知道该怎么做?

You need to study Responsive Design. 您需要学习响应式设计。 But I'll tell you the big key: media queries. 但我会告诉您一个重要的关键:媒体查询。

With CSS like this 像这样的CSS

@media only screen and (max-width: 500px) {
  #mydiv {
    width: 80%;
  }
}

@media only screen and (min-width: 501px) {
  #mydiv {
    width: 50%;
  }
}

you can do all you need. 您可以做所有您需要的。 In fact, for some screen sizes you can set #menu1 to display:none, and #menu2 to display:block, and thereby show entirely different layouts dynamically based on the screen size. 实际上,对于某些屏幕尺寸,您可以将#menu1设置为display:none,将#menu2设置为display:block,从而根据屏幕尺寸动态显示完全不同的布局。

Try this link for a very minimal example you can play with http://www.w3schools.com/css/tryit.asp?filename=tryresponsive_breakpoints 尝试此链接以获取一个非常简单的示例,您可以使用它http://www.w3schools.com/css/tryit.asp?filename=trysensitive_breakpoints

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM