0

Hi I have a 1px png file,which I am trying to set as a background image for two divs which are adjacent to each other horizontally.The html and css are as under:-

<div id='one'>hi</div>
<div id='two'>hello</div>

The css is like this

div {
    width: 50%;
    height: 50%
}
#one, #two {
    background-image: url(/images/image.png);
    background-repeat: repeat;
}

Now the problem here is in between the two divs a black border automaticaly appears when the image is set. I dont want the two divs to be seen as separate blocks.Please help. Am totally new to css and need help:-)!

7
  • I'm not getting the border, jsfiddle.net/Jn8fL, make sure you don't have a margin/padding set on the DIV from somewhere else. You can also try border: 0; Commented Sep 22, 2010 at 16:51
  • It is not one full image but a small image which is to be repeated. Have edited the css in the main post.Missed that out earlier!no border:0 does not help Commented Sep 22, 2010 at 17:31
  • Why would you want to repeat a 1x1 image? Just set background-color and you're done. Commented Sep 22, 2010 at 17:53
  • Are you using a transparent png? Might be some overlap which causes the perceived border. Try changing the width to 49% and see what happens... Commented Sep 22, 2010 at 17:56
  • Inrbob, seems like that would have been the problem.. However am quite new to all these images stuff and understanding things like transparency and alll.. but you and Stan seem to be on the same line and his solution worked! Commented Sep 22, 2010 at 18:44

3 Answers 3

1

I'd be willing to bet that the image you are using has alpha transparency (that is, the image is partially transparent), and what you're seeing is a one-pixel overlap between the two divs. Either make sure that the container is an even number of pixels wide, or put the divs inside another container and use the background on that instead.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Stan! That worked wonderfully.. I put them in one container and applied the background.. actually there were a couple of divs ,which were stuck into one other.. this worked thanks again!
0

like robert, i'm also not getting the border, but i do get some repeats. see if this works for you:

#one, #two{
    background-image:url(99785.jpg);
    background-repeat: no-repeat;
    borders: 0
    }

1 Comment

The image is small 1 px-height, width, which is repeated. It repeats itself perfectly in each of the divs which are both with 200px height, width, but at the borders of the two div they leave a line. I dont get this problem in chrome , but in firefox.
0

The problem is caused by a couple of interacting things.

First, make sure you are using the html strict doctype. This will help mitigate a lot of the formatting issues between browsers around divs. See alistapart for a description and list of real doctypes to use and quirksmode for a detailed comparison of them.

Second, you will more than likely have to set the margin of your divs to 0. Browsers have different default settings. A strict doctype will alleviate most of this, but there are usually other areas you have to overcome as well.

Also, you might want to grab firebug for firefox and leverage chromes dev tools. firebug will actually show you what all of the margins / padding / everything else is being set to. The Chrome tools don't give you a pretty picture with the details but you can see what the margins/padding/etc are in the Computed Style section.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.