填充一定比例的屏幕宽度 [英] Padding of a certain percentage of screen width

查看:129
本文介绍了填充一定比例的屏幕宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主容器div,我希望它完全保留在屏幕的顶部,例如屏幕宽度的 10%。这种方式,我不会有非统一的屏幕尺寸等问题。



我已经找到一个肮脏的解决方法,它将一个 1px 1px 背景颜色的图像,在div之前,然后将其设置为屏幕宽度的 10%。但是这看起来很肮脏,不是吗?有没有更好的解决方案?

解决方案

我觉得非常优雅的解决方案是将页面插入表格中,

你会有这个:

 < HTML> 
< head>< title> ...< / title>< / head>
< body>
< table id =content>< tr>< td>

您整个页面都在这里...

< / td>< / tr>< / table>
< / body>
< / html>

现在使用下面的样式简单地决定页面的大小:

  #content {

width:850px;
margin-left:auto;
margin-right:auto;

}


I have a main container div, and I'd like it to be margined from the top of the screen exactly, for example, 10% of the screen width. This way I won't have problems with non-uniform screen sizes etc..

I already found a dirty workaround which is putting a 1px by 1px image of the color of the background, right before the div, and then style it to have 10% of the width of the screen. But this looks quite dirty, doesn't it? Is there any better solution?

解决方案

The solution I find very elegant is to insert the page in a table, beginning right after the body, and terminating right before it.

You'd have this:

<html>
<head><title>...</title></head>
<body>
<table id="content"><tr><td>

    Your whole page comes here...

</td></tr></table>
</body>
</html>

Now simply decide the size of the page, using the style:

#content {

    width: 850px;
    margin-left: auto;
    margin-right: auto;

}

这篇关于填充一定比例的屏幕宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆