Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

CSS Forum


You are currently viewing our CSS Forum as a guest. Please register to participate.
Login



Reply
Different kind of centering. Scalable background image.
Old 04-28-2009, 04:48 PM Different kind of centering. Scalable background image.
Novice Talker

Posts: 5
Name: Michael
Location: Vancouver, BC
Trades: 0
I've been searching for a solution to this problem for a bit, and I would like to be able to do it entirely within CSS.

Essentially, I have a scalable layout with max and min widths, but I also want the background image to scale with the layout as well. I've managed to figure that out, but unfortunately the image doesn't want to center no matter what I do. It always wants to be top left.

Here's what I've got for the background image CSS.
Code:
#background img {
    position: absolute;
    z-index: -100;
    width: 130%;
    max-width: 1700px;
    min-width: 1400px;
    margin-left: auto;
    margin-right: auto;
    border: 0;
    margin: 0;
    padding: 0;
}
I've tried centering the background div that it's in, as well as using text-align: center; on the body as well.

At this point the site is in the proof of concept stage so yes it's buggy. Here's the site so you can see what I'm trying to do.

PS. If anyone is curious about the name of the site, it's a photography project I'm working on and I'm documenting where the shirts are made and their contents and will have all the statistics and information about them.
mwhc is offline
Reply With Quote
View Public Profile Visit mwhc's homepage!
 
 
Register now for full access!
Old 04-28-2009, 08:32 PM Re: Different kind of centering. Scalable background image.
vangogh's Avatar
Post Impressionist

Posts: 10,689
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
The problem is in the absolute positioning. When you use positioning you take that element out of the normal document flow. By default your image is set at top: 0 and left: 0, which is why you see it in the upper left.

You probably want to place the image inside a div and center the div. Set the image width to 100% and then it should scale with the div and the browser.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 04-28-2009, 10:11 PM Re: Different kind of centering. Scalable background image.
Novice Talker

Posts: 5
Name: Michael
Location: Vancouver, BC
Trades: 0
Quote:
Originally Posted by vangogh View Post
The problem is in the absolute positioning.
Without absolute positioning though the image ends up on top of everything else.

I have the image inside a div, and trying to center that div doesn't seem to work either. But I may not be doing it the right way.
mwhc is offline
Reply With Quote
View Public Profile Visit mwhc's homepage!
 
Old 04-29-2009, 02:07 PM Re: Different kind of centering. Scalable background image.
LadynRed's Avatar
Defies a Status

Posts: 10,016
Location: Tennessee
Trades: 0
The we really need to see the rest of the code to see what's going on with the document.
__________________
Web Goddess & Web Standards Evangelist :) - Tables Be Gone !!

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

LadynRed is offline
Reply With Quote
View Public Profile
 
Old 04-29-2009, 02:14 PM Re: Different kind of centering. Scalable background image.
Novice Talker

Posts: 5
Name: Michael
Location: Vancouver, BC
Trades: 0
I've posted the link to the site above, and here's some more of the code.

Code:
body {
    background: #FFFFFF;
    font: 16px Helvetica, Arial, sans-serif;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

#background {
}

#background img {
    position: absolute;
    z-index: -100;
    width: 130%;
    max-width: 1700px;
    min-width: 1400px;
    margin-left: auto;
    margin-right: auto;
    border: 0;
    margin: 0;
    padding: 0;
}

#container {
    position: relative;
    margin: 0 auto;
    width: 80%;
    max-width: 1000px;
    min-width: 760px;
    height: 100%;
    text-align: left;
}
And the html where it's placed.

Code:
<div id="background">
<img src="images/background.jpg">
</div>
mwhc is offline
Reply With Quote
View Public Profile Visit mwhc's homepage!
 
Old 04-29-2009, 06:22 PM Re: Different kind of centering. Scalable background image.
vangogh's Avatar
Post Impressionist

Posts: 10,689
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
The way I would have set this up is to use the image as a background either on the body or a wrapper div and then place your content inside the wrapper div. The wrapper div would be centered.

The only limitation is the image wouldn't scale the way you want, but that's usually not an important thing to me.

What I think you're going to need to do is use % for the top and left to center your image instead of trying to use margins. Once you start using positioning the margins don't have the same meaning since the position element is no longer in the normal document flow. It's as though it's not there to other elements.

Try using % on the top and left for the image to see if you can center it that way.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 04-29-2009, 06:31 PM Re: Different kind of centering. Scalable background image.
Average Talker

Posts: 18
Name: Jon
Location: Southern California
Trades: 0
Couple items I notice immediately are:

IE does not recognize MIN or MAX heights/widths.

The code you have provided renders differently cross browsers, so unless you omitted some of your CSS you need to zero-out these default settings which cause these errors - usually most annoying and apparent in IE.

Your actual image is 1424 height x 2000 width. Based on the width you have allowed, this image would always appear off-center even if somene actually had their screen resolution set to accommodate a view port that large.

My suggestion would be to place the image in the CSS as a background of the main divide, in this case #container. That way you would not have to use absolute positioning. There are several sticky threads posted in the lobby of the CSS forum that discuss issues inherent with using absolute which doesn't seem necessary for what you're after.

This quite possibly could create other issues for you, but it opens up more options for solutions.

CSS like...

Code:
 
#background {
height:130%;
width:130%;
    margin-left: auto;
    margin-right: auto;
    border: 0;
    margin: 0;
    padding: 0;
  background: url(image/background.jpg) center center no-repeat;
}
HTML change to the #background divide, opposed to the whole #container. This way, your text will sit on-top of the image.

Code:
 
<div id="background">
<div id="menu">
<h1><a href="#">people</a></h1>
<h1><a href="#">fabrics</a></h1>
<h1><a href="#">stats</a></h1>
<h1><a href="#">resources</a></h1>
</div>
</div>
*simultaneous post with vangough.

Last edited by LoganKonlan; 04-29-2009 at 06:32 PM..
LoganKonlan is offline
Reply With Quote
View Public Profile
 
Old 04-30-2009, 03:35 PM Re: Different kind of centering. Scalable background image.
Novice Talker

Posts: 5
Name: Michael
Location: Vancouver, BC
Trades: 0
Well, I've got it about 98% there, but yeah in IE it just doesn't work at all. Oh well, I'll have to abandon this direction. It was fun figuring it out though.

I ended up with a pretty convoluted solution. The only thing is at smaller screen widths the background shifts.

Here is how it looks now.

Here's the CSS I had to use. Does it make sense? No. Does it work? Sorta.

Thanks for the help.

Code:
#backgroundbox {
    text-align: center;
    z-index: -100;
    min-width: 1700px;
}

#backgroundmargin {
    margin: 0 auto;
}

#background {
    position: absolute;
    width: 140%;
    left: 50%;
    margin-left: -70%;
}

#background img {
    width: 97.5%;
    max-width: 1700px;
    min-width: 1300px;
}
mwhc is offline
Reply With Quote
View Public Profile Visit mwhc's homepage!
 
Old 04-30-2009, 06:49 PM Re: Different kind of centering. Scalable background image.
vangogh's Avatar
Post Impressionist

Posts: 10,689
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
Your page is looking pretty good. I am viewing in Firefox and not IE. What you're trying seems like it should be simple, but I think combining the scaling image with the image being in the background is harder than it looks.

At least you had fun with it and probably learned a few things.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 05-01-2009, 05:36 PM Re: Different kind of centering. Scalable background image.
Novice Talker

Posts: 5
Name: Michael
Location: Vancouver, BC
Trades: 0
Thanks vangogh, I quite like it as well. Pondering now whether I should have a static version only for IE, or go in a different direction.

You can tell I'm not a web designer, because there are many things that do not work with IE on that page.

PS. I was just in Lafayette, CO a couple weekends ago. Drove across country and stopped in to see friends. I spent a couple weeks there last year, would love to live in Boulder.
mwhc is offline
Reply With Quote
View Public Profile Visit mwhc's homepage!
 
Old 05-01-2009, 06:44 PM Re: Different kind of centering. Scalable background image.
vangogh's Avatar
Post Impressionist

Posts: 10,689
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
Lafayette, just down the road. Boulder is beautiful. I passed through town about 12 years and never left.

IE can be frustrating, but it's not as hard to work with as many make it out to be. You want to code to the standards. If you do your page will usually work with most browsers and then just need a few tweaks for IE. Then you can use conditional comments to serve IE and different versions of IE it's own unique stylesheet.

Another tip is to use a css reset which will set default values for things so they're the same across browsers.

It just takes a little practice and experience.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Reply     « Reply to Different kind of centering. Scalable background image.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.33361 seconds with 12 queries