SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jun 2008
    Location
    Seattle, WA
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to center a background image?

    Hi guys,

    I set my background image centered, after I save and preview it, it looks great but as soon as I try resizing the window, the image stays fixed and won't stay in the center while the rest of the content stays centered.

    I guess my question is, is there any way at all to make my background image always stay centered on any screen size?

    If so, please explain how. A step by step would really be appreciated since I'm real nice and not so good with coding.


    Thanks

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,789
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    What code are you using to centre it?
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,478
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you show me an example of what you have so far?

  4. #4
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, if you're using css to center it.. the best way would be to use this code in the body section of your css

    Code:
    background-image: url(YOURIMAGEHERE);
    background-repeat: no-repeat;
    background-position: center top;

  5. #5
    SitePoint Wizard bronze trophy Black Max's Avatar
    Join Date
    Apr 2007
    Posts
    4,029
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)
    This is a very frequent question, with several unsuspected permutations depending on different people's usages and such. It might be worth it for the forum managers to consider a sticky thread with a compilation of solutions.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •