Jump to content

Archived

This topic is now archived and is closed to further replies.

Voodum

CSS <div> Problem

Recommended Posts

[a href=\"http://img174.imageshack.us/img174/6529/space4jd.jpg\" target=\"_blank\"]The problem[/a]

Thats the link to a picture of the problem. I dont know why it does it, but it adds the spacing between the divs.
Ive tried putting them on the same line, and making the margin and padding to 0, but I've had no luck so far.

The CSS code is below, and then followed by the html code.

[code]
.arttop {
background:url(images/index_08.jpg) repeat-x;
height:70px;
margin:0;
padding:0;
}

.mainbg {
background:url(images/index_10.jpg) repeat-x #FFFFFF;
border-left:#CCCCCC solid 1px;
border-right:#CCCCCC solid 1px;
margin:0;
padding:0;
}

.bar {
background:url(images/index_12.jpg) repeat-x;
height:25px;
margin:0;
padding:0;
}
[/code]

Now for the html

[code]<div class="arttop">hi</div>
<div class="mainbg">
  <p>hi</p>
  <p>h</p>
  <p>h</p>
  <p>h</p>
  <p>h</p>
  <p>h</p>
</div>
<div class="bar">hi</div>[/code]

Share this post


Link to post
Share on other sites
At the start of all my CSS code, I tend to use this:
[code]* { margin: 0px; padding: 0px; } [/code]
This way, I'm the only one who specifies padding and borders.
Is the background image shorter then the <div> itself? If it is, try making it smaller.
If that doesn't work, try giving either element either a negative top or a negative bottom margin.

Share this post


Link to post
Share on other sites
Negative margins worked a treat! Many thanks. [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /]

Share this post


Link to post
Share on other sites
rather than use negiyive margins reduce the height of your .arttop class by 2 or 3 pixels as I think you have set the height too high or something and so you get that 2 or 3 pixs white line.

Share this post


Link to post
Share on other sites
If the height might change based on content, you can add a background color to cover up the gab.

It's always a good idea to add a background color of the last pixel of you background image when you repeat-x or y

Something like this

[code].arttop {
background:url(images/index_08.jpg) repeat-x #186b9f;
height:70px;
margin:0;
padding:0;
}[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.