简体   繁体   English

如何消除html中div之间的差距?

[英]How to remove the gap between div in html?

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. 在我的网页中,我在容器div中使用了3个div。我正在尝试消除div之间的不必要的差距。

  • (1)Top bg image (1)顶部bg图像
  • (2)Middle bg image (2)中间bg图像
  • (3)Bottom bg image (3)底部bg图像

I am trying to adjust these 3 divs so that it can look like one bg image. 我试图调整这3个div,使它看起来像一个bg图像。 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 */
}

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! 你现在可以使用CSS来获得角落!

Here is a website which can help with those: 这是一个网站,可以帮助那些:

http://www.css3.info/preview/rounded-border/ http://www.css3.info/preview/rounded-border/

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) top_part,middle_part,bottom_part都可以有边距或填充,只要它不是一个接触另一个的“边”(即:#top的底部和#middle的顶部需要触摸而不是移动)

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. 您可能需要将它们添加到绝对定位项目内,但这是另一篇文章。

在这种情况下,保证金重置非常适合我

我遇到了同样的问题,唯一可以解决这个问题的方法是在浏览器中使用InspectElement并继续将边距更改为某个-ve值。

You may want to set the padding to 0 rather than 10px and set the height of the divs explicitly rather than using auto. 您可能希望将填充设置为0而不是10px并明确设置div的高度而不是使用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... 或者创建一个包装器div,它可以容纳整个背景图像,这样您就不必担心它们在某些浏览器中没有对齐...

It was the Problem with the Top bg image size. 这是Top bg图像大小的问题。 Size of the image is 45 pix and I took it the size of the div as 47 pix. 图像的大小是45像素,我把它的大小作为47像素。 By decreasing the size of the div had solved my problem.Thanks a lot to Dawson and DBz for the help. 通过减小div的大小已经解决了我的问题。谢谢Dawson和DBz的帮助。

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

margin:-16px

当我有三个(顶部,中部,底部)背景并且每个都是div标签时,这个工作

margin:-8px;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM