Results 1 to 7 of 7

Thread: CSS Body Background Image Positioning

  1. #1
    Senior Member
    Join Date
    May 2004
    Location
    Stafford, West Midlands
    Posts
    642
    Thanks
    3
    Thanked
    0 times in 0 posts

    CSS Body Background Image Positioning

    Hi,

    I've been wondering this for a while so thougth it was worth posting to see if anyone knew if there was a fix.

    My web site has a background image (arrows and circles) that can be seen to the left and right of the page. I have used the following CSS to add it:

    Code:
    body { 
    	margin-top: 0; 
    	margin-bottom: 0; 
    	background: url(../layout/background.jpg) no-repeat top center #ebebeb;
    	}
    Everything works fine, but when the window is made smaller the jpeg background image stays centred to the window and not to the web page. A little hard to explain to please have a look at what I mean:

    www.timsportfolio.co.uk

    Is it possible to put a min-width or something on the body so that the background image stays in the correct place in smaller windows?

    Thanks for any help

  2. #2
    Not a good person scaryjim's Avatar
    Join Date
    Jan 2009
    Location
    Gateshead
    Posts
    15,196
    Thanks
    1,231
    Thanked
    2,291 times in 1,874 posts
    • scaryjim's system
      • Motherboard:
      • Dell Inspiron
      • CPU:
      • Core i5 8250U
      • Memory:
      • 2x 4GB DDR4 2666
      • Storage:
      • 128GB M.2 SSD + 1TB HDD
      • Graphics card(s):
      • Radeon R5 230
      • PSU:
      • Battery/Dell brick
      • Case:
      • Dell Inspiron 5570
      • Operating System:
      • Windows 10
      • Monitor(s):
      • 15" 1080p laptop panel

    Re: CSS Body Background Image Positioning

    Quote Originally Posted by Timmy!!! View Post
    Is it possible to put a min-width ... on the body...
    Yes.


  3. Received thanks from:

    Timmy!!! (04-08-2009)

  4. #3
    bored out of my tiny mind malfunction's Avatar
    Join Date
    Jul 2003
    Location
    Lurking
    Posts
    3,923
    Thanks
    191
    Thanked
    187 times in 163 posts
    • malfunction's system
      • Motherboard:
      • Gigabyte G1.Sniper (with daft heatsinks and annoying Killer NIC)
      • CPU:
      • Xeon X5670 (6 core LGA 1366) @ 4.4GHz
      • Memory:
      • 48GB DDR3 1600 (6 * 8GB)
      • Storage:
      • 1TB 840 Evo + 1TB 850 Evo
      • Graphics card(s):
      • 290X
      • PSU:
      • Antec True Power New 750W
      • Case:
      • Cooltek W2
      • Operating System:
      • Windows 10
      • Monitor(s):
      • Dell U2715H

    Re: CSS Body Background Image Positioning



    On a serious note there are plenty of websites out there that seem to just preserve the size of the side bars and let the middle / main part shrink - you'd have to split the background image in two and define 3 columns / boxes (I think - been a while since I did any web work). Weirdly enough I just dropped my screen res to 1024 x 768 and it scales down fine when the window is maximised (even though the pane is then too small to render everything) but as soon as you shrink the window it goes over to the left again.
    Last edited by malfunction; 04-08-2009 at 10:47 AM.

  5. Received thanks from:

    Timmy!!! (04-08-2009),yamangman (04-08-2009)

  6. #4
    Senior Member
    Join Date
    May 2004
    Location
    Stafford, West Midlands
    Posts
    642
    Thanks
    3
    Thanked
    0 times in 0 posts

    Re: CSS Body Background Image Positioning

    Thanks for the help guys.

    scaryjim - unfortunately it doesn't work, all it does is push the main page over to the right if the window is smaller but the background image stays centred no matter what.

    malfunction - Yeah the 3 coloum approach could be used here but it would force smaller resolution screens to display those arrows etc and push the main middle bit to the right by quite a bit.

    Interesting about the maximised window displaying it correctly, how odd. Sounds like a browser issue then perhaps. Although it does do the same in firefox as well as IE.

  7. #5
    Senior Member
    Join Date
    May 2004
    Location
    Stafford, West Midlands
    Posts
    642
    Thanks
    3
    Thanked
    0 times in 0 posts

    Re: CSS Body Background Image Positioning

    Fixed it! Hooray!

    The solution was to add the min-width css attribute to the html, not the body.

    Code:
    html {
    	min-width: 1020px;
    	}
    
    body { 
    	margin-top: 0; 
    	margin-bottom: 0; 
    	background: url(../layout/background.jpg) no-repeat top center #ebebeb;
    	}
    With this the background stays in the correct position even when the resolution is far smaller than the site itself.

    For some reason both IE and Firefox are not reloading the new CSS file I've uploaded so the background still moves (even with a ctrl-f5).

    Cheers for all the help.

  8. #6
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts

    Re: CSS Body Background Image Positioning

    CSS 'min-width' is not ie6 compat.
    To err is human. To really foul things up ... you need a computer.

  9. #7
    Senior Member
    Join Date
    May 2004
    Location
    Stafford, West Midlands
    Posts
    642
    Thanks
    3
    Thanked
    0 times in 0 posts

    Re: CSS Body Background Image Positioning

    The internet is not ie6 compat...

    For a big website like hexus I guess they have to worry about ie6. I have coded for Firefox/Safari/IE8/IE7. IE6 can take a hike.

    Thanks for the information though

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. LaTeX2html problem...
    By bsodmike in forum General Discussion
    Replies: 4
    Last Post: 15-12-2010, 03:51 PM
  2. Replies: 8
    Last Post: 19-01-2008, 05:23 PM
  3. Body Image
    By IBM in forum General Discussion
    Replies: 53
    Last Post: 21-02-2007, 02:47 PM
  4. Image problems in IE (probably CSS related)
    By Dorza in forum Software
    Replies: 4
    Last Post: 08-05-2005, 11:50 PM

Posting Permissions

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