Jump to content

Repeating Background Image (I dont want it to repeat)


monkeytooth

Recommended Posts

Alright, lets see..

 

I'm fairly new to css so bare with me if this is a stupid question.

 

I want to take an image and use it as a background image in a DIV tag. Which that much I can do. However. I can't seem to get it to stop from repeating. After the Height of the DIV exceeds past the images size.

 

Info about the pic. Its a gradient background. Its about 3 pixels wide, and about 550px in height. The concept is to save bandwidth use a smaller image. Problem is that when using background:no-repeat; the image is only the image. What is desired is the image repeat left to right somehow, but not up and down.

 

Anyone know how I can fix this issue?

Link to comment
Share on other sites

Oh wow, didn't know bout that one, thank you. Im going to assume that "Y" would be for up/down?

 

Also the piece you just helped me with, how cross compatiable is that browser wise as well as how version compatiable is that do you know? Meaning does it work across the board from IE to Safari, and will it work in something like IE 4 (you'd be suprised how many hits a couple sites I am starting to undertake recently get hit with older browsers).

Link to comment
Share on other sites

Oh wow, didn't know bout that one, thank you. Im going to assume that "Y" would be for up/down?

 

Also the piece you just helped me with, how cross compatiable is that browser wise as well as how version compatiable is that do you know? Meaning does it work across the board from IE to Safari, and will it work in something like IE 4 (you'd be suprised how many hits a couple sites I am starting to undertake recently get hit with older browsers).

 

and background-repeat has been around for a long time. if you want to see the browser compatibilities go here:

http://www.w3schools.com/css/css_reference.asp

Link to comment
Share on other sites

It is true that he may not need to add the color to the background, but I'd like to remind you that it's always good practice to specify one. Sometimes the background image may not load, and by at least specifying a color, the browser can show some color. Otherwise, it will become transparent and potentially create non-contrasting colors.

 

- TheFilmGod

Link to comment
Share on other sites

TheFilmGod, I read your post wrong...didn't see that you changed the style attribute to background instead of background-repeat. In that case, I agree and the full background style should look like:

background: #FFF url(path/to/background.jpg) repeat-x scroll top left;

Link to comment
Share on other sites

Shorthand for the "background" property is very cool and I couldn't live without it. Particularly positioning.

 

background: #fff url('myimage.gif') top left no-repeat;

background: #fff url('myimage.gif') top center no-repeat;

background: #fff url('myimage.gif') top right no-repeat;

background: #fff url('myimage.gif') center left no-repeat;

background: #fff url('myimage.gif') center center no-repeat;

background: #fff url('myimage.gif') center right no-repeat;

background: #fff url('myimage.gif') bottom left no-repeat;

background: #fff url('myimage.gif') bottom center no-repeat;

background: #fff url('myimage.gif') bottom right no-repeat;

 

You can also use percentages and/or pixels (which work great for images as bullets):

 

background: #fff url('myimage.gif') 10px 50% no-repeat fixed; (positions the img 10px left and 50% relative to the text or other element - for bullets or text links with an img this is perfect)

 

background: #fff url('myimage.gif') 30% 0 no-repeat fixed; (positions the img 30% from the left and top relative to the element)

 

I always list color, url, position/position, repeats:

 

background: #fff url('myimage.gif') top left repeat-y;  (position starts at the top left of the element and tiles vertically)

 

background: #fff url('myimage.gif') bottom rightrepeat-x;  (position starts at the bottom right of the element and tiles horizontally)

 

background: #fff url('myimage.gif') top center repeat;  (position starts at the top center of the element and tiles horizontally and vertically)

 

background: #fff url('myimage.gif') center bottom no-repeat;  (position starts at the center and bottom of the element once and doesn't tile)

 

Here is a link to the w3c school for the background element:

 

http://www.w3schools.com/css/css_background.asp

Link to comment
Share on other sites

Unless you are using CSS sprites for something. Then it's essential.

 

I don't always state top left either, but there is something to be said for it. If you are going to use the shorthand declaration method, then expressly setting each of the variable is a good practice in case the defaults change sometime in the future. I know this is unlikely with the background position, but it can still be considered good practice.

Link to comment
Share on other sites

If you are going to use the shorthand declaration method, then expressly setting each of the variable is a good practice ...

 

Particularly when first teaching someone css. I make it a practice to not rely on defaults whenever it comes to positioning of any element.

 

I personally like to use the top left (or 0 0) because I DO use a lot of other background img positioning within my css for various other purposes (like img bullets).

 

I also prefer using percentages for the vertical alignment of a background img in relation to text.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.