空div(样式:高度)将不会显示 [英] Empty div (with style: height) will not display

查看:412
本文介绍了空div(样式:高度)将不会显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

令人难以置信的简单的HTML片段-但未显示我的期望。

Incredibly simple piece of HTML - but not displaying how I would expect.

我正在尝试创建一个空div,该空白div在页面顶部显示为空白,其 style = height:400px;

I'm trying to create an empty div that displays as whitespace on the top of the page, with style="height: 400px;"

即使我指定了高度,我的空div也不会显示。我在这里想念什么?

Even though I have specified a height, my empty div will not display. What am I missing here?

更新:我的主要问题是:即使设置了高度,为什么不显示空div?或者,显示空div所需的基本样式规则是什么?

UPDATE: my main question is: Why does an empty div not display even if it has a height set? Or, what are the basic style rules needed to display an empty div?

完整代码:

<html>
<head><title>Site Name</title>
</head>
<body>
<div style="height:400px; width:100%; margin:0; padding:0; position:absolute;"></div>
<div style="width: 50%; margin: auto;">
<img src="logo.gif"></div> 

<div style="width: 50%; margin: auto;"></div>

</body>
</html>


推荐答案

如果只想添加空格,请尝试以下

If you just want to add white space try this

<div style="height:400px; width:100%; clear:both;"></div>

FIDDLE

或者您可以像 body {padding-top:400px; }

这篇关于空div(样式:高度)将不会显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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