如何去除html中div之间的间隙?
我被这个问题困住了,无法摆脱这个问题。请帮我。
在我的网页中,我在容器 div 内使用了 3 个 div。我正在尝试删除不需要的间隙div 之间。
- (1)顶部背景图像
- (2)中间背景图像
- (3)底部背景图像
我正在尝试调整这 3 个 div,使其看起来像一张背景图像。我的中间部分和底部部分已完全调整,但顶部部分和中间部分之间有一些间隙,我试图删除但无法删除。
请参阅我在此处附加的图像,该图像显示了顶部和中间部分之间的间隙。请参阅我用于放置图像的样式表数据。
提前致谢。
#main_container {
background-repeat:no-repeat;
width:645px;
float:left;
padding-bottom:10px;
overflow:hidden;
height:auto;
}
#middle_part {
background-image: url('/DiscoverCenter/images/apps_mid.png');
background-repeat:repeat-y;
width:645px;
padding-bottom:10px;
overflow:hidden;
height:auto;
clear:both;
position:relative;
display: block;
vertical-align: bottom;
}
#top_part {
background-image:url('/DiscoverCenter/images/apps_top.png');
width:645px;
top:0px;
height:47px; /* actual height of the top bg image */
clear:both;
position:relative;
display: block;
vertical-align: bottom;
}
#bottom_part {
background-image:url('/DiscoverCenter/images/apps_btm.png');
width:645px;
height:24px; /* actual height of the bottom bg image */
}
I am stuck with this problem and not able to come out of this. Please help me.
In my webpage, I have used 3 divs inside a container div.I am trying to remove the unwanted gap between the div.
- (1)Top bg image
- (2)Middle bg image
- (3)Bottom bg image
I am trying to adjust these 3 divs so that it can look like one bg image. My middle part and bottom part are adjusted completely but top part and middle part have some gap in between that i am trying to remove but not able to.
Please refer to the image which i have attached here which shows the gap between top and middle part.Please refer the stylesheet data I had used for placing the images.
Thanks in advance.
#main_container {
background-repeat:no-repeat;
width:645px;
float:left;
padding-bottom:10px;
overflow:hidden;
height:auto;
}
#middle_part {
background-image: url('/DiscoverCenter/images/apps_mid.png');
background-repeat:repeat-y;
width:645px;
padding-bottom:10px;
overflow:hidden;
height:auto;
clear:both;
position:relative;
display: block;
vertical-align: bottom;
}
#top_part {
background-image:url('/DiscoverCenter/images/apps_top.png');
width:645px;
top:0px;
height:47px; /* actual height of the top bg image */
clear:both;
position:relative;
display: block;
vertical-align: bottom;
}
#bottom_part {
background-image:url('/DiscoverCenter/images/apps_btm.png');
width:645px;
height:24px; /* actual height of the bottom bg image */
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您是否考虑过使用重置?
将其添加到顶部
但是,当我们讨论这个主题时:您是否使用图像来获得圆角?现在你可以使用 CSS 来获得圆角!
这是一个可以帮助解决这些问题的网站:
http://www.css3.info/preview/圆角边框/
Have you considered using a reset?
Add that to the top
However, while we are on the subject: Are you using images to get rounded corners? You can use CSS to get rouned corners nowadays!
Here is a website which can help with those:
http://www.css3.info/preview/rounded-border/
一些调整将修复它:
top_part、middle_part、bottom_part 都可以有边距或填充,只要它不是接触另一边的“边”(即:#top 的底部和#middle 的顶部需要触摸而不移动
)在这里,看看需要进行哪些演示调整。我删除了顶部、中间、底部的定位,因为它与所需的效果无关。您可能需要添加它们才能将项目绝对定位在其中,但那是另一篇文章了。
Some adjustments will fix it:
top_part, middle_part, bottom_part can all have margins or padding as long as it's not a "side" that touches the other (ie: bottom of #top and top of #middle need to touch and not move)
Start here, and see what presentation adjustments need to be made. I removed positioning from top, middle, bottom because it isn't relevant for the desired effect. You may need to add them in for absolutely positioning items inside of them, but that's another post.
您可能希望将填充设置为 0 而不是 10px,并显式设置 div 的高度而不是使用 auto。
或者创建一个包装 div 来容纳整个背景图像,这样您就不必担心它们在某些浏览器中不对齐...
You may want to set the padding to 0 rather than 10px and set the height of the divs explicitly rather than using auto.
Or alternatively create a wrapper div that accommodates the entire background image so that you don't have to worry about them not aligning in some browsers...
这是顶部背景图像尺寸的问题。图像的大小是 45 像素,我将 div 的大小设为 47 像素。通过减小 div 的大小解决了我的问题。非常感谢 Dawson 和 DBz 的帮助。
It was the Problem with the Top bg image size. Size of the image is 45 pix and I took it the size of the div as 47 pix. By decreasing the size of the div had solved my problem.Thanks a lot to Dawson and DBz for the help.
我设法自己解决了这个问题
I managed to solve the problem myself by
在这种情况下,边距重置对我来说非常适合
margin reset works perfect for me in such cases
我遇到了同样的问题,解决此问题的唯一方法是在浏览器中使用 InspectElement不断将边距更改为某个值。
I came across the same issue, the only way I could fix this is by using InspectElement in browser & keep changing the margin to some -ve value.
当我有三个(顶部、中间、底部)背景并且每个背景都是一个 div 标签
margin:-8px;
时,此方法有效This worked when i had three (top, middle, bottom) backgrounds and each was a div tag
margin:-8px;