如何去除html中div之间的间隙?

发布于 2024-10-19 15:18:47 字数 1254 浏览 2 评论 0原文

我被这个问题困住了,无法摆脱这个问题。请帮我。

在此处输入图像描述

在我的网页中,我在容器 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.

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

不奢求什么 2024-10-26 15:18:47

您是否考虑过使用重置?

* {
    padding: 0px;
    margin: 0px
}

将其添加到顶部

但是,当我们讨论这个主题时:您是否使用图像来获得圆角?现在你可以使用 CSS 来获得圆角!

这是一个可以帮助解决这些问题的网站:

http://www.css3.info/preview/圆角边框/

Have you considered using a reset?

* {
    padding: 0px;
    margin: 0px
}

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/

梦过后 2024-10-26 15:18:47

一些调整将修复它:

#main_container, #top_part, #middle_part, #bottom_part { margin:0; padding:0; width:645px; }
#main_container {
    float:left; 
    } /* setting height:auto and overflow:hidden won't do anything */

#top_part {
    background:url('/DiscoverCenter/images/apps_top.png') no-repeat;
    clear:both;
    height:47px;
    }
#middle_part {
    background:url('/DiscoverCenter/images/apps_mid.png') repeat-y;
    display: block; /* only needed if you're assigning this id to an inline element */
    min-height: ?? /* assure this element can expand, but never collapses completely */
    vertical-align: bottom;
    }
#bottom_part {
    background:url('/DiscoverCenter/images/apps_btm.png');
    height:24px;
    }

top_part、middle_part、bottom_part 都可以有边距或填充,只要它不是接触另一边的“边”(即:#top 的底部和#middle 的顶部需要触摸而不移动

)在这里,看看需要进行哪些演示调整。我删除了顶部、中间、底部的定位,因为它与所需的效果无关。您可能需要添加它们才能将项目绝对定位在其中,但那是另一篇文章了。

Some adjustments will fix it:

#main_container, #top_part, #middle_part, #bottom_part { margin:0; padding:0; width:645px; }
#main_container {
    float:left; 
    } /* setting height:auto and overflow:hidden won't do anything */

#top_part {
    background:url('/DiscoverCenter/images/apps_top.png') no-repeat;
    clear:both;
    height:47px;
    }
#middle_part {
    background:url('/DiscoverCenter/images/apps_mid.png') repeat-y;
    display: block; /* only needed if you're assigning this id to an inline element */
    min-height: ?? /* assure this element can expand, but never collapses completely */
    vertical-align: bottom;
    }
#bottom_part {
    background:url('/DiscoverCenter/images/apps_btm.png');
    height:24px;
    }

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.

止于盛夏 2024-10-26 15:18:47

您可能希望将填充设置为 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...

蘑菇王子 2024-10-26 15:18:47

这是顶部背景图像尺寸的问题。图像的大小是 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.

岁吢 2024-10-26 15:18:47

我设法自己解决了这个问题

margin:-16px

I managed to solve the problem myself by

margin:-16px
云仙小弟 2024-10-26 15:18:47

在这种情况下,边距重置对我来说非常适合

margin reset works perfect for me in such cases

无远思近则忧 2024-10-26 15:18:47

我遇到了同样的问题,解决此问题的唯一方法是在浏览器中使用 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.

红颜悴 2024-10-26 15:18:47

当我有三个(顶部、中间、底部)背景并且每个背景都是一个 div 标签

margin:-8px;时,此方法有效

This worked when i had three (top, middle, bottom) backgrounds and each was a div tag

margin:-8px;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文