Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: background position with repeat?

Tags:

css

I currently have an image repeating on y, but I want it to start 20 px down from where the div starts....

how do I do that?

like image 928
NullVoxPopuli Avatar asked Sep 21 '10 15:09

NullVoxPopuli


2 Answers

Maybe you should use :after or :before for this, because there's no need to add extra markup in your HTML. Like this:

.container{
    height:400px;
    background:red;
    position:relative;
    width:400px;
}
.container:after{
    content:"";
    position:absolute;
    top:20px;
    left:0;
    right:0;
    bottom:0;
    background:url(http://lorempixel.com/400/200) repeat-y;
}

Check this http://jsfiddle.net/h6K9z/

It works in IE8 & above. For IE7 or IE6 you can give extra DIV for this.

like image 100
sandeep Avatar answered Oct 02 '22 16:10

sandeep


I don't think simply combining background-position and background-repeat e.g. repeat-y 0 20px will work. Assuming this jsFiddle sample represents OP's case, the solution should make the green background starts at (vertical) 20px; the "Hello there!" text shouldn't sit on top of the green background.

My answer is this cannot be done plainly by CSS; meaning, you might want to change your HTML structure to accomplish your goal. However, I am starting a bounty hoping others to come up with better answers.

like image 39
moey Avatar answered Oct 02 '22 14:10

moey