• Log in or sign up for an account here: https://www.sythe.org/login

Align div content relative to background?

MohtasaUnique

Grand Master

Retired Global Moderator
Joined
Sep 1, 2007
Sythe Gold
690
Messages
6,681
(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:
7joYs.jpg

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:
7jp2R.jpg
.......
7jp4e.png


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 n4n0
Discord Verified
Two Factor Authentication User
Community Participant
Spam Forum Participant
Sythe's 10th Anniversary
Sythe Awards 2011 Winner
The div has to be um. relative. Hold on.
 
<3 n4n0
Discord Verified
Two Factor Authentication User
Community Participant
Spam Forum Participant
Sythe's 10th Anniversary
Sythe Awards 2011 Winner
Code:
margin-left:auto;
margin-right:auto;

will work but it will be as wide as the page.
 
<3 n4n0
Discord Verified
Two Factor Authentication User
Community Participant
Spam Forum Participant
Sythe's 10th Anniversary
Sythe Awards 2011 Winner
Code:
margin-left:auto;
margin-right:auto;

will work but it will be as wide as the page.

Or wait.

Code:
margin-left:auto;
margin-right:auto;
width: 700;
 
<3 n4n0
Discord Verified
Two Factor Authentication User
Community Participant
Spam Forum Participant
Sythe's 10th Anniversary
Sythe Awards 2011 Winner
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
 
Code:
margin-left:auto;
margin-right:auto;

will work but it will be as wide as the page.
as said on FB, that's what it is currently (in case anyone else has input to give me too)
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

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
 
<3 n4n0
Discord Verified
Two Factor Authentication User
Community Participant
Spam Forum Participant
Sythe's 10th Anniversary
Sythe Awards 2011 Winner
Put it within a centered div that contains the image.
 
Runescape Gamblingrunescape gambling
Back
Top