mieche — 2011-04-26T20:32:14-04:00 — #1
I've seen this done in a few different places where the background image resizes to fit the window...I'm wondering if there is a way for this to work for the entire page of a portfolio site so the header, main image and footer always fit on the page...hope that makes sense.
Obviously there would need to be a minimum height, but what I need is for the height to fit the users window size so there is no scrolling...
The site I'm creating won't have a background image, but that is the only way I have seen it done so far.
paulob — 2011-04-27T06:42:08-04:00 — #2
It depends on exactly what dynamics you need.
You obviously can't have a site that fits all windows without scaling all the elements and that would be silly anyway.
If you just want a background that fills the viewport height then you are probably looking at a sticky footer effect. You can read up on it in the CSS faq (see link in my sig - there is also a faq on 100% height you may find useful).
If on the other hand you want a header and footer always fixed to the top and bottom of the viewport then you are looking at fixed positioning which is something different again.
We'd need to see a picture of your design and what you would expect to happen to the layout at various sizes.
Suffice to say that usually doing none of the above is the best approach and content should dictate what the page looks like Just let it flow and adjust to screen sizes automatically. Everyone expects to scroll vertically so there is no need to avoid this.
mieche — 2011-04-27T15:13:06-04:00 — #3
Unfortunately my photographer clients prefer sites that do not scroll vertically. My latest client is asking if it is possible to have everything (header, footer, content) adjust to the users window height...I'm still trying to determine if he is just concerned with the home page or if this is something he would like on all pages.
The site I am creating will not have a background image...you are welcome to take a look at the current pages at Wegle Photography
Since this is not my first client to express concern about scrolling I figured it is best to start looking into options other than designing to a 600px max height.
paulob — 2011-04-27T17:36:29-04:00 — #4
You could certainly use media queries to swap background images for smaller background images depending on the sites width and height. It would be a little awkward to change any foreground images without using scripting of some sort.
Here's some links that show media queries in action.
Different Stylesheets for Differently Sized Browser Windows | CSS-Tricks
CSS3 Media Queries and creating adaptive layouts - Robert's talk
CSS3: Media Queries: width and height // Think Vitamin Membership
Media queries don't work in ie8 and under though and you;d have to supplement it with some js for IE8 and under.
You can scale images with css but the results aren't generally that good and do depend on the image used.
CSS Proportional Image Scale - CSS Tutorials - hasLayout.net by Zoffix Znet
If your clients don't like scrolling then perhaps they can show you a site that performs the way they want. It seems that they are looking for something like a flash site instead.
mieche — 2011-04-27T17:46:16-04:00 — #5
I think I may have miss worded what I am looking for, but just to be extremely clear...there is no background image on the site I am creating...I was just using it as an example!
paul_wilkins — 2011-04-27T18:08:18-04:00 — #6
Given a standard three-level vertical split of header/content/footer, is it possible for CSS to to give the content a flexible vertical height, so that the footer always remains at the bottom of the page?
paulob — 2011-04-28T09:06:54-04:00 — #7
You can do something like this with css only. It really needs tidying up and tying into that javsascript resize routine I posted earlier.
I assume this was the sort of think that was required?
paulob — 2011-04-28T09:55:25-04:00 — #8
Here was my attempt at adding a little js to resize the image but needs Paul W's magic touch as I don't think the logic is sound (and of course needs to be made to work on multiple images and not just the one image).
mieche — 2011-04-28T14:52:16-04:00 — #9
Yes this is exactly what I have been thinking of!!! Thank you.
Now to see if I can get it to work with my site.
mieche — 2011-04-28T15:53:44-04:00 — #10
Ok, hopefully one last question...I've got everything working except for the right side border...I'm not sure why it is not coming up? Any suggestions?
mieche — 2011-04-28T17:10:29-04:00 — #11
I found the fix for the border.
As I'm continuing to play with this I'm wondering if it really is the right thing as it doesn't seem like the image is resizing so much as the footer is covering it up...not really what I'm after, I want to see the whole image.
paulob — 2011-04-28T17:38:58-04:00 — #12
The border makes the image too big and the bottom of the image is being hidden by the overflow:hidden anyway.
I've added a border to my example but you need to keep the same format.
The new version is here.
The element with class="x" is the trick that vertically aligns the image and cannot be omitted.
paulob — 2011-04-28T17:40:32-04:00 — #13
Yes that's because you omitted the important bits from my routine and basically you are just hiding the image whereas mine is being scaled within limits and vertically centred.
See my above demo for the latest code.
mieche — 2011-04-28T18:22:09-04:00 — #14
paul_wilkins — 2011-04-28T18:32:05-04:00 — #15
It it was in a code review there would be a few improvements to make there, but the logic of what's happening does appear to be sound.
In light of the recent comment from the OP, I'll see if the good folks in the Wordpress forum have anything to add.
mieche — 2011-04-28T18:59:21-04:00 — #16
Thanks for the move Paul W...I appreciate all the help and hard work both of you have given me on this situation. I didn't realize there was a wordpress forum, hooray!
paulob — 2011-04-29T06:03:35-04:00 — #17
Yes I've no idea how you will implement this in wordpress but you do need to maintain the structure I've given.
specifically this section.
<div id="outer"> <div class="content"><b class="x"></b><img id="theImage" class="test" title="Audi A3" src="[images/carscale.jpg](http://www.sitepoint.com/forums/view-source:http://www.pmob.co.uk/temp/images/carscale.jpg)" alt=""/></div> </div>
If you nest extra elements or don't keep the b element next to the image then you break the structure. As soon as you nest another element you break the routines because there is no longer any height to work with.
You need to strip away everything that is not needed and end up with a structure as in my example above which shows that it will work once everything is in the right place.
outer contains the available space between footer and image and the class="x" must be 100% height of this space because it then forces the image to vertical-align within that space. (See here for the details of the technique).
If you add extra nested elements inside then you break that relationship and nothing will align.
mieche — 2011-04-29T11:54:34-04:00 — #18
Paul O'B...thanks again for all your help, but unfortunately I can't change the structure of wordpress so hopefully someone here will be able to help.
I'm using Thematic framework with a child theme for my customizations.
paulob — 2011-04-29T14:34:09-04:00 — #19
If you post the minimum html that you have to work with I'll see if it's possible to fit what's needed into your structure.
mieche — 2011-04-29T19:18:26-04:00 — #20
ugh...I'm headed to redesign. Thank you so much for the help, I truly, truly appreciate it. Hopefully after redesign the client won't be throwing any other curveballs my way.