在 CSS 中设置身体大小?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8547805/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 02:24:51  来源:igfitidea点击:

Set body size in CSS?

css

提问by Daan

I just created a lockscreen theme for my iPhone. It works, but for some reason I cannot remove the black background space of the body, i.e. resize the body along the right and bottom edge of the lockscreen.

我刚刚为我的 iPhone 创建了一个锁屏主题。它可以工作,但由于某种原因,我无法删除主体的黑色背景空间,即沿锁屏的右侧和底部边缘调整主体的大小。

I created a short slideshow so you get the.. indeed: Photobucket slideshow link.

我创建了一个简短的幻灯片,因此您可以看到……确实:Photobucket 幻灯片链接

Here's the relevant HTML and complete CSS code. Note that I added many unnecessary '0px' properties just to see if they'd make a difference:

这是相关的 HTML 和完整的 CSS 代码。请注意,我添加了许多不必要的 '0px' 属性只是为了看看它们是否会有所作为:

<body>
<div id="background">
<img src="LockBackground.jpg" width="320" height="480">
</div>

<div id="labels">
    <div id="clock">//e.g. 6:12 AM
    </div>
    <div id="day">//e.g. Sunday
    </div>
    <div id="date">//e.g. 5 Aug
    </div>
</div>
</body>

CSS:

CSS:

    *{ margin: 0px; padding: 0px; border: 0px; }
    body  { background-color: #000; border: 0px; margin: 0px; padding: 0px; position: absolute; font-family: Helvetica Neue; font-size: 50px; color: #fff; width: 320px; }
    img { border: 0px; margin: 0px; padding: 0px; top: 0px; left: 0px; width: 320px; z-index: 0; }
    #labels { position: absolute; width: 290px; top: 50%; margin: -0.7em 0 0 30px; }
    #day { line-height: 0.8; }
    #date { position: absolute; margin-top: 18px; line-height: 0.6; }

回答by ACarter

Surely you just need body {width:100%; height:100%;}.

当然你只需要body {width:100%; height:100%;}.

It may be more complex than this, but I can't think why it would be.

它可能比这更复杂,但我想不出为什么会这样。

You could also try img {width:100%; height:100%;}.

你也可以试试img {width:100%; height:100%;}