background image on the piss

Discussion in 'HTML & Website Design' started by onlinegamesnz, Aug 23, 2010.

  1. #1
    so heres an easy one, or so i thought.

    im trying to insert a background image with no reapeat and center it on the page. dead cener x and y. then insert an iframe over it. when i try to center the background heres what happens.

    http://onlinegamesnz.orcon.net.nz/site2/index.html

    the image is up the top and half of it cut off

    image: http://onlinegamesnz.orcon.net.nz/site2/background.png

    Any ideas?

    cheers
     
    onlinegamesnz, Aug 23, 2010 IP
  2. xbren

    xbren Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The background image (in the CSS) needs to be set to 'fixed' (it is set to 'scroll' by default). The background image will remain in the centre/middle, even when you scroll then.

    Alternatively, you can create a div and position it to be the same size as the image and then centre it horizontally and vertically (not always that simple, but plenty of CSS tricks around).
     
    xbren, Aug 23, 2010 IP
  3. onlinegamesnz

    onlinegamesnz Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    So what's a good CSS code for this?
     
    onlinegamesnz, Aug 23, 2010 IP
  4. onlinegamesnz

    onlinegamesnz Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This worked. background-attachment:fixed;
    Thanks. One more question.


    i want to put an iframe right in the middle of that picture with some navigation above the iframe.
    When i add the iframe in dreamweaver (which it just displays as yellow text, really annoying)
    i cant drop it down without entering (enter, enter, enter) you know. is there another waY?

    cheers
     
    onlinegamesnz, Aug 23, 2010 IP
  5. xbren

    xbren Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You need to give the iframe an ID and use CSS to give the iFrame a set size and then use CSS to centre it. The trick is to offset it with negative margins.

    So if it is 400px wide, then you need to have margin-left: -400px; (note the minus).

    e.g.:

     
    xbren, Aug 24, 2010 IP
  6. onlinegamesnz

    onlinegamesnz Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    So does this go in a separate stylesheet or within the same page. CSS in the <head>? And where in that code do I put the ID?
     
    onlinegamesnz, Aug 24, 2010 IP
  7. xbren

    xbren Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yeah, put the CSS with the rest of the CSS (in the head if you have it there).

    ID tag goes inside the iframe tag <iframe id="center"> etc.
     
    xbren, Aug 24, 2010 IP
  8. onlinegamesnz

    onlinegamesnz Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Ok that makes sense. One more thing what about on the CSS code where is the Id specified. How does it know which iframe to apply this CSS to?

    Thanks for your help
     
    onlinegamesnz, Aug 24, 2010 IP
  9. xbren

    xbren Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    The "iframe#center {" tells it to look for an iframe with the ID of "center" and apply the CSS contained within the brackets.
     
    xbren, Aug 24, 2010 IP
  10. onlinegamesnz

    onlinegamesnz Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Ok cool thanks. So will this load over the image correctly even if there are different screen resolutions or text sizes?
     
    onlinegamesnz, Aug 24, 2010 IP
  11. onlinegamesnz

    onlinegamesnz Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    /nchdesign.dnserver.net.nz/site2
     
    onlinegamesnz, Aug 24, 2010 IP
  12. xbren

    xbren Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Should do. Experiment with the margins, you may need to increase how much it is offset by.
     
    xbren, Aug 24, 2010 IP
  13. onlinegamesnz

    onlinegamesnz Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Ok thank you!
     
    onlinegamesnz, Aug 24, 2010 IP
  14. onlinegamesnz

    onlinegamesnz Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    it doesnt work.. here my code

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    body {
    	background-color: #000;
    	background-repeat: no-repeat;
    	background-position:center;
    	background-attachment:fixed;
    }
    .style1 {
    	margin-right: 0px;
    	margin-top: 0px;
    }
    .style3 {
    	margin-left: 81px;
    	margin-top: 118px;
    }
    iframe#center {
    position: absolute;
    width: 900px;
    height: 400px;
    top: 50%;
    margin-top: -200px;
    left: 50%;
    margin-left: -200px;
    }
    </style>
    </head>
    
    <body style="background-image: url('back2.png')">
    <form id="form1" runat="server" style="width: 951px; height: 558px" class="style3">
    <div style="position: absolute; left: 246px; top: 176px; width: 766px; height: 480px">
    	<iframe name="I1" frameborder="0" allowtransparency="true" id="center" style="width: 767px; height: 480px; left: 0px; top: 0px;" src="content.html" class="style1">
    	</iframe></div>
    </form>
    </body>
    </html>
    
    HTML:
     
    onlinegamesnz, Aug 24, 2010 IP
  15. onlinegamesnz

    onlinegamesnz Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    ok so got it to psition with the CSS. but the problem still persists when i change text size etc its all over the place


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    body {
    	background-color: #000;
    	background-repeat: no-repeat;
    	background-position:center;
    	background-attachment:fixed;
    }
    .style1 {
    	margin-right: 0px;
    	margin-top: 0px;
    }
    .style3 {
    	margin-left: 81px;
    	margin-top: 118px;
    }
    iframe#center {
    position: absolute;
    width: 900px;
    height: 400px;
    top: 50%;
    margin-top: 40px;
    left: 50%;
    margin-left: 80px;
    }
    </style>
    </head>
    
    <body style="background-image: url('back2.png')">
    <form id="form1" runat="server" style="width: 951px; height: 558px" class="style3">
    <div style="position: absolute; left: 246px; top: 176px; width: 766px; height: 480px">
    	<iframe name="I1" frameborder="0" allowtransparency="true" id="center" style="width: 767px; height: 480px; left: 0px; top: 0px;" src="content.html" class="style1">
    	Your browser does not support inline frames or is currently configured not to display inline frames.
    	</iframe></div>
    </form>
    </body>
    </html>
    
    HTML:
     
    onlinegamesnz, Aug 24, 2010 IP
  16. onlinegamesnz

    onlinegamesnz Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    so heres the thing. In safari the irame appears different to in IE, other then the scrollbar color. Its in a dirrerent postion

    View in ie and safari
    nchdesign.dnserver.net.nz/site1/

    how can i make it so its locked to the image and is center to the image in both safari and ie? and possibly even when you change the text size? and resolution would be good

    ANY IDEAS PLEASE!!!!??

    cheers
     
    onlinegamesnz, Aug 25, 2010 IP
  17. xbren

    xbren Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    Why are you using an iframe? Wouldn't it be better to use a div, put the content in the div and define a set width and height and make the content/overflow scroll?
     
    xbren, Aug 25, 2010 IP
  18. longcall911

    longcall911 Peon

    Messages:
    1,672
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    0
    #18
    I believe that you now need to learn about CSS on your own. Xbren has been very very patient. He answered your first question very clearly. Then you asked another, and another. Now it seems that you expect him to troubleshoot your code.

    I suggest that you buy a book or take a course.
     
    longcall911, Aug 25, 2010 IP
  19. onlinegamesnz

    onlinegamesnz Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #19
    Can you scroll a div? How's that possible
     
    onlinegamesnz, Aug 25, 2010 IP