【发布时间】:2015-07-17 23:47:24
【问题描述】:
好的,我知道 margin:0 样式表确保我的全屏图像周围没有白色背景边框,完全适合屏幕,周围没有任何边框/边距。问题是,我只能将此样式表应用于正文标记。但随后 我的 body 标记中的所有文本与图像一起完全向左移动,隐藏了一些文本。 基本上,我希望 margin:0 样式仅适用于图像和不是文字。我尝试了各种方法,例如将该标签应用于 div 并将图像放入 div 中……等等,但它不起作用。 margin 属性似乎只适用于 body 标签。
下面的猫头鹰图片是完全全屏的,工作正常,但它下面的一些文本向左移动了两个(因为边距现在为 0)并被隐藏了。
<html>
<head>
<style>
body
{
margin:0;
}
</STYLE>
</head>
<body>
<div id="test">
<img src="owl.jpg">
</div>
THIS TEXT GETS SHIFTED TO THE LEFT HIDING SOME OF IT
</body>
</html>
请帮忙!
参考 1
<html>
<head>
<style>
.test
{
margin:0;
}
</style>
</head>
<body>
<div class="test" id="test">
<img src="owl.jpg">
</div>
The image now has a margin around it and is not completely full-screen. Same thing for this text
</body>
</html>
【问题讨论】:
-
文本从
body继承边距值。只需创建另一个 CSS 类#text{ margin: 20px; }或您想要的任何文本边距,然后将文本包装在<div id='text'> -
我试过了,但没用。就像我说的,到目前为止,marine:0 样式只适用于我的 body 标签。请参阅参考 #1
-
你用的是什么浏览器?我已经尝试过最新的 FF 和 IE 9,看起来还不错。我尝试了 2 个不同的大图像,并且文本在图像下方完全可见。