CSS边距的常见问题
我不知道这个问题对其他用户来说有多常见,但对我来说,它很常见,而且我不知道为什么会发生。
但让我解释一下症状。 :)
当我使用 css 和 div 进行布局时,很多时候我都会遇到 margin 停止工作的情况。它可能会增加左侧和右侧的空间,但通常不会增加顶部和底部的空间。
有时,div 顶部的边距会导致页面下方出现不需要的空间。
有人有这个问题的经验吗?我可能做错了什么?
当然,所有 div 都已正确关闭,因此并不那么明显。我知道,我知道,没有真实的例子,很难回答。我只是扔出一根绳子,希望能有救世主。谢谢!
I do not know how common this problem is for other users, but for me, it's pretty common and I have no real idea why it is happening.
But let me explain the symptoms. :)
When ever I do a layout using css and divs I many times end up with some place where margin just stops working as it should. It could be that it adds space to the left and right but usually not top and down.
Other times a margin on top of a div results in an unwanted space further down on the page.
Anyone with experience of this problem? And what am I probably doing wrong?
All divs are of course properly closed, so it isn't that obvious. And I know, I know, it's super hard to answer width no real example. I'm just throwing out a rope gere and hoping for a savior. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为问题在于
float
和margin
一起使用。例如,如果您有一个带有float:right
的div
和另一个后面没有 float 的 div,则边距将不适用!这两个元素之间不会应用任何边距。除非你也为第二个元素设置了一个浮动!但请记住,在这些情况下,边距适用于两个元素的内容。不是为了边界。内容将正确对齐,但边框不会!
这是一个常见问题,我们可以将其称为浏览器错误!
如果您有任何具体问题,请告诉我们。
I think the problem is with
float
andmargin
together. margin will not apply for example if you have adiv
withfloat:right
and another div without float after it ! no margin between these two elements will be applied. unless you set a float for second element too !but remember in these situations,
margin
applied for contents of both elements. not for borders. content will align correctly but borders not!this is a common problem that we can call it as a BROWSER BUG!
If you have eny specific problem let us to know.
如果你可以发布一些代码..它将很有帮助。查看这些网站并尝试看看你哪里出了问题。
http://www.w3.org/TR/CSS21/box.html
http://www.w3schools.com/css/css_boxmodel.asp
if u can post some code..it will be helpful. see these sites and try to see where ur going wrong..
http://www.w3.org/TR/CSS21/box.html
http://www.w3schools.com/css/css_boxmodel.asp