WordPress.org

Ready to get started?Download WordPress

Forums

CSS: Using background-position and background-repeat (3 posts)

  1. NixWanning
    Member
    Posted 7 years ago #

    I need to know if there's a way to use both background-repeat and background-position in CSS on the same element.

    Basically, I have a semi-transparent PNG that has a gradient for the first 300px followed by a flat 1px (height) by 200px (width) PNG (repeated vertically till the end of the element). The element does not have a fixed height (ie it's fluid).

    The problem I'm facing is getting the 1px PNG to start repeating after 300px, and not before (as background-repeat does it both ways).

    Is there a hack for this?

  2. Jonathan Landrum
    Member
    Posted 7 years ago #

    Well, for one thing, why make it 1px high? That sure will waste a lot of bandwidth on larger pages. The one I just made for a site I'm building is 200px high, so it will only repeat a few times on most pages.

    I've basically done what you're talking about, too. The way I did it is to wrap the element with another div, and set the repeating background to that element. Then, the inner element has the gradient, and since it's next in line, its background will go on top of the first one. In the end, you'll have a gradient merging into a solid, repeating colour until the end of the document.

  3. NixWanning
    Member
    Posted 7 years ago #

    Hi jonlandrum,

    Thanks for replying.

    Having it 1px high decreases the file size and I believe that it'll require less disk space/bandwidth.

    I understand the method you've given, in fact, I tried it out before, but the problem lies with the fact that these are semi-transparent PNGs.

    If you stack 2 semi transparent PNGs on top of each other, then the "gradient" part will be more defined than the rest of the body of the element, and the gap where the gradient ends is very obvious.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.