如何让div到达浏览器窗口的边缘? [英] How to make divs reach edges of browser window?

查看:144
本文介绍了如何让div到达浏览器窗口的边缘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看了看,但没有找到这个答案 - 只是

很多引用这个或那个黑客应该修复

问题(对某些人来说这是一个问题)。


如果我指定了div并希望它能够达到浏览器窗口的全宽

,它不是。 div的任何一端都有大约10个像素的
保证金。我可以修复通过将我的左边

和右边距设置为-10px,但通过这样做,我感觉

我正在做一些从未想过的事情。 br />

首先,就我所知,为什么不要自然地触摸浏览器窗口的

边缘。第二,什么是正确/最好/

最差/正确?让他们触摸浏览器窗口边缘的方法。


请参阅以下html:


< html>

< head>


< style type =" text / css">

<! -

..bluearea {

保证金:0px;

填充:5px;

宽度:自动;

颜色:白色;

背景颜色:蓝色;

}

..redarea {

margin-left: -10px;

margin-right:-10px;

填充:5px;

宽度:自动;

颜色:白色;

背景颜色:红色;

}

- >

< /风格>


< / head>

< body>


< div class =" bluearea">

为什么这个蓝色的乐队没有碰到浏览器窗口的边缘?

< / div>


< div class =" redarea">

虽然这个红色乐队有吗?

< / div>


< / b ody>

< / html>

I have looked and looked and not found the answer to this one - just
lots of references to this or that "hack" that is supposed to fix the
problem (and it is a problem to some people).

If I have a div specified and want it to reach across the full width
of the browser window, it doesn''t. There is an approximately 10-pixel
margin on either end of the div. I can "fix" this by setting my left
and right margins to -10px, but by doing so, I get the feeling that
I''m doing something that was never intended.

So first, why DON''T div''s naturally, as far as I can tell, touch the
edges of the browser window. And second, what is the right/best/
least worst/"correct" way to make them touch the browser window edges.

See the following html:

<html>
<head>

<style type="text/css">
<!--
..bluearea {
margin: 0px;
padding: 5px;
width: auto;
color: white;
background-color: blue;
}
..redarea {
margin-left: -10px;
margin-right: -10px;
padding: 5px;
width: auto;
color: white;
background-color: red;
}
-->
</style>

</head>
<body>

<div class="bluearea">
Why does this blue band not touch the edges of the browser window?
</div>

<div class="redarea">
While this red band does?
</div>

</body>
</html>

推荐答案

困惑写道:
我看了看,但没找到这个的答案 - 只是
很多引用这个或那个黑客应该解决
问题(对某些人来说这是一个问题)。

如果我指定了一个div并希望它达到整个宽度
浏览器窗口,它不是。 div的两端都有大约10像素的边距。我可以修复通过将我的左边缘和右边距设置为-10px,但通过这样做,我感觉
我正在做一些从未打算过的事情。

所以首先,据我所知,为什么不自然地触摸,触摸浏览器窗口的边缘。第二,什么是正确/最好/最差最差/正确?让它们触摸浏览器窗口边缘的方法。
I have looked and looked and not found the answer to this one - just
lots of references to this or that "hack" that is supposed to fix the
problem (and it is a problem to some people).

If I have a div specified and want it to reach across the full width
of the browser window, it doesn''t. There is an approximately 10-pixel
margin on either end of the div. I can "fix" this by setting my left
and right margins to -10px, but by doing so, I get the feeling that
I''m doing something that was never intended.

So first, why DON''T div''s naturally, as far as I can tell, touch the
edges of the browser window. And second, what is the right/best/
least worst/"correct" way to make them touch the browser window edges.




body {margin:0,padding:0;}


- -

William Tasso - http://WilliamTasso.com


在帖子< news:le ******************************* *@4ax.com>

疑惑地说:
in post <news:le********************************@4ax.com >
puzzled said:
如果我指定了div并希望它达到整个宽度
在浏览器窗口中,它没有。
If I have a div specified and want it to reach across the full width
of the browser window, it doesn''t.




body {margin:0; padding:0;}


< ; div> 100%< / div>

-

brucie



body{margin:0;padding:0;}

<div>100%</div>
--
brucie


body {margin:0;填充:0;}


+ -------


谢谢大家。我发誓我花了三个小时试图在发布之前找到答案


body{margin:0;padding:0;}

+-------

Thanks people. I swear I spent three hours trying to find the answer
before posting.


这篇关于如何让div到达浏览器窗口的边缘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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