0

I'm specifying a color hex code as the background-color of a really long div. However, i'd like this color to be only repeated horizontally, from left to right, in the first part of the and not go down any further.

Can that be done using background-repeat:repeat-y or is there another method?

Ali
  • 261,656
  • 265
  • 575
  • 769

4 Answers4

5

Colors have no height...they just exist, without dimensions. If you want a visual distinction between your background color and the rest of the document, you'll need to use a solid image as your background-image:

div.className {
  background-image:url("images/background.jpg");
  background-position:left top;
  background-repeat:repeat-x; // Causes repeat from left-to-right only
}
Sampson
  • 265,109
  • 74
  • 539
  • 565
2

Do you mean repeating background color or an image? I assume an image becaues repeating a background color makes no sense. And yes this is the correct way:

#mydiv {
  background-image: url(images/background.png);
  background-repeat: repeat-x;
}
cletus
  • 616,129
  • 168
  • 910
  • 942
1

The background-repeat CSS property defines how background images are repeated. A background image can be repeated along the horizontal axis, the vertical axis, both, or not repeated at all. When the repetition of the image tiles doesn't let them exactly cover the background, the way adjustments are done can be controlled by the author: by default, the last image is clipped, but the different tiles can instead be re-sized, or space can be inserted between the tiles.

http://www.handycss.com/how/how-to-repeat-a-background-image-horizontally-with-css/

Rana Adnan
  • 11
  • 1
-1

You can achieve this without a file when creating an 1px image and put it into your CSS encoded as base64, or by using multiple html elements and positioning. You can not specify a background size for a plain color defined in pure CSS (without using the image trick) at this time.

Also see Is embedding background image data into CSS as Base64 good or bad practice?

Community
  • 1
  • 1
Chris
  • 1