Setting Background

Discussion in 'CSS' started by michalka, Apr 1, 2011.

  1. #1
    Hi,
    How to set particular area of a image as background for a div.
     
    michalka, Apr 1, 2011 IP
  2. Sepehr

    Sepehr Peon

    Messages:
    568
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Sepehr, Apr 1, 2011 IP
  3. extremike

    extremike Peon

    Messages:
    44
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Sepehr is correct - if you have a DIV that is smaller than the image you can position the image accordingly. For example, if you want to use just the bottom, right corner of the image you would declare the background as follows:

    background:url(images/background.gif) no-repeat right bottom;
    Code (markup):
    If you want to use the bottom left corner it would be:

    background:url(images/background.gif) no-repeat right bottom;
    Code (markup):
    and so on...

    You can also exactly position the image like so:

    background:url(images/background.gif) no-repeat 30px 20px;
    
    Code (markup):
    In this example the background image would be positioned 30px from the left of the div, 20px from the top.
     
    extremike, Apr 1, 2011 IP
  4. michalka

    michalka Peon

    Messages:
    79
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for the info. Now its working fine.
     
    michalka, Apr 1, 2011 IP