调整浏览器窗口大小时均匀减小空间 [英] Reducing the space equally when resizing browser window
问题描述
调整浏览器窗口大小时,浏览器只会减少元素后的空间。
When resizing the browser window the browser just reduces the space after the element. I want to decrease the space equally on the left and right as it is done in Facebook.
这是我的代码
CSS:
body{
margin-left:10%;
margin-right:10%;
}
HTML:
<body>
Some content
.
.
.
.
</body>
首先我想到给出一个 min-width
到身体。但是具有较小屏幕尺寸的计算机将是一个问题。 min-width
将不会是很好的解决方案。
First I thought of giving a min-width
to body. But computers having less screen size will be a problem. Also min-width
will not be good solution.
推荐答案
向
身体添加
80%
和 margin-right
到 auto
用于中心对齐
Just give width 80%
to your body
and give margin-left
and margin-right
to auto
for center aligning
body{
margin:0 auto;
width:80%;
}
建议:
给样式给body是不好的做法,给你的页面顶部父div的样式
To give styles to body is not a good practice, give styles to top parent div in your page
像这样,
<body>
<div class="container">
all page elements.....
</div>
</body>
CSS:
container{
margin:0 auto;
width:80%;
}
这篇关于调整浏览器窗口大小时均匀减小空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!