Align div content relative to background?

Discussion in 'Web Programming' started by MohtasaUnique, Mar 4, 2014.

Align div content relative to background?
  1. Unread #1 - Mar 4, 2014 at 9:25 PM
  2. MohtasaUnique
    Joined:
    Sep 1, 2007
    Posts:
    6,681
    Referrals:
    2
    Sythe Gold:
    690
    Discord Unique ID:
    158831078964985856
    Discord Username:
    Tony#2235

    MohtasaUnique Grand Master
    Retired Global Moderator

    Align div content relative to background?

    (Sorry about the annoying format, makes the text easier to see next to all the screenshots)
    Ok so I'm a HUGE noob when it comes to web dev, I've only just started learning. I've got the following code:​

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <style>
    html, body {
        min-height: 100%
    }
    body {
        background-color: #ffffff;
        background-image: url(banner.png), url(footer.png), url(filler.png);
        background-position: center top, center bottom, center center;
        background-repeat: no-repeat, no-repeat, repeat-y;
    }
    </style>
    </head>
    
    <body>
    <style>
    div.content {
    	width:700px;
    	padding:10px;
    	border:2px solid #004688;
    	margin:auto;
    	margin-top:400px;
    	margin-bottom: 135px;
    }
    </style>
    <div class="content">test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test</div>
    </body>
    </html>
    And here is the result:
    [​IMG]
    Looks good, everything is aligned properly. But then when the page is resized to a size smaller than the div container, the div and the background fall out of alignment. Here's what it looks like:
    [​IMG].......[​IMG]

    How do I make it so that the div stays aligned relative to the background image? OR How do I make the background image stop at the left-most edge when resizing, so it stays center until the window is too small for it? The background image ends at the very end of the shadow graphic, the white in the background is just a background-color property.​
     
  3. Unread #2 - Mar 4, 2014 at 9:32 PM
  4. SuF
    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary

    SuF Legend
    Pirate Retired Global Moderator

    Align div content relative to background?

    The div has to be um. relative. Hold on.
     
  5. Unread #3 - Mar 4, 2014 at 9:35 PM
  6. SuF
    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary

    SuF Legend
    Pirate Retired Global Moderator

    Align div content relative to background?

    Code:
    margin-left:auto;
    margin-right:auto;
    
    will work but it will be as wide as the page.
     
  7. Unread #4 - Mar 4, 2014 at 9:37 PM
  8. SuF
    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary

    SuF Legend
    Pirate Retired Global Moderator

    Align div content relative to background?

    Or wait.

    Code:
    margin-left:auto;
    margin-right:auto;
    width: 700;
     
  9. Unread #5 - Mar 4, 2014 at 9:40 PM
  10. SuF
    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary

    SuF Legend
    Pirate Retired Global Moderator

    Align div content relative to background?

    try display: block;

    for the text no idea what it does

    but yea make a divcenter that shit background the image then put your content div in that div
     
  11. Unread #6 - Mar 4, 2014 at 9:41 PM
  12. MohtasaUnique
    Joined:
    Sep 1, 2007
    Posts:
    6,681
    Referrals:
    2
    Sythe Gold:
    690
    Discord Unique ID:
    158831078964985856
    Discord Username:
    Tony#2235

    MohtasaUnique Grand Master
    Retired Global Moderator

    Align div content relative to background?

    as said on FB, that's what it is currently (in case anyone else has input to give me too)
    I'll try this after work, all attempts thusfar to put the background inside a div has fallen flat, but it's probably because I'm just doing it wrong
     
  13. Unread #7 - Mar 4, 2014 at 9:46 PM
  14. SuF
    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary

    SuF Legend
    Pirate Retired Global Moderator

    Align div content relative to background?

    Put it within a centered div that contains the image.
     
< Looking for site to code and work with! [free] | Looking for Quotes for a website >

Users viewing this thread
1 guest


 
 
Adblock breaks this site