视图端口高度和宽度的CSS定义

时间:2014-11-04 09:32:20

标签: css

我有一个关于div高度的问题,div.need中没有任何内容可以自动调整浏览器高度。 需要了解视口高度和宽度

1 个答案:

答案 0 :(得分:0)

如果您使用

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

您的网站将适合视口。然后内部的div需要

div {
  height: 100%;
}

也可以填充视口。



html, body, div {
  height: 100%;
  margin: 0;
  padding: 0;
}
html {
  background: #00ff00;
}
body {
  background: rgba(255,0,0,.5);
}
div {
  background: rgba(0,0,255,.3);
}

<html><body><div>This is inside the div. HTML has green background, body is red and the div is blue, since they overlay each other the resulting background should be greyish.</div></body></html>
&#13;
&#13;
&#13;