本文介绍了如何在body元素中获得全宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎样才能让网站自动适应页面?
How would I be able to get a website to auto-fit in the page?
这是一个不需要滚动的景观设计.
It's a landscape design which needs no scrolling.
推荐答案
您应该将 body
和 html
设置为 position:fixed;
,然后设置right:
, left:
, 顶部:
和 底部:
到 0;
.这样,即使内容溢出也不会超出视口的限制.
You should set body
and html
to position:fixed;
, and then set right:
, left:
, top:
, and bottom:
to 0;
. That way, even if content overflows it will not extend past the limits of the viewport.
例如:
<html>
<body>
<div id="wrapper"></div>
</body>
</html>
CSS:
html, body, {
position:fixed;
top:0;
bottom:0;
left:0;
right:0;
}
警告:使用此方法,如果用户将窗口变小,内容将被截断.
Caveat: Using this method, if the user makes their window smaller, content will be cut off.
这篇关于如何在body元素中获得全宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!