+ -
当前位置:首页 → 问答吧 → 前端滴高手们来看看。。关于边界少了一半的问题。

前端滴高手们来看看。。关于边界少了一半的问题。

时间:2011-04-27

来源:互联网


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <style type="text/css"> .box{ margin:10px; background-color:#999; height:auto; overflow:hidden; zoom:1} .inner{ margin:20px; background-color:#F00;} </style> </head> <body style="background-color:#FCC"> <div class="box"> <div class="inner">Inner</div> <div class="inner">Inner2222222222222222</div> </div> </body> </html>
 提示:您可以先修改部分代码再运行

作者: shiwoya   发布时间: 2011-04-27

-_!! 。。把代码贴出来就不能写我的问题了。。。。相信大家也看出问题在哪了。。中间的边界应该是40的。可是却只有20.。怎么解决这个问题呢?

作者: shiwoya   发布时间: 2011-04-27

盒子模型,两个元素之间,一般以margin大的为准,margin 不会相加
要么设一个为40,要么两个都设为40,看布局而定
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <style type="text/css"> .box{ margin:10px; background-color:#999; height:auto; overflow:hidden; zoom:1} .inner{ margin:40px 20px; background-color:#F00;} </style> </head> <body style="background-color:#FCC"> <div class="box"> <div class="inner">Inner</div> <div class="inner">Inner2222222222222222</div> </div> </body> </html>
 提示:您可以先修改部分代码再运行

作者: kuivv   发布时间: 2011-04-27

这么说如果一个是10一个是20那么中间就只是20.。不会是30了?。。呃? 如果是用循环出来。中间距离要求40.。那么就只能给两DIV定义40,,不能定义20了。。。

作者: shiwoya   发布时间: 2011-04-27

其实我好像问你。。是不是所有浏览器都是这样的。。如果是的话还好。。不是的话又要脑壳痛了。

作者: shiwoya   发布时间: 2011-04-27

这个问题就是传说中的“margin叠加”,楼主google一下,大把的解决办法~

作者: kele5240   发布时间: 2011-04-27

其实我只是无聊问问。。如果真遇到这样的情况。。margin不行就用padding

作者: shiwoya   发布时间: 2011-04-27