Pixelpost

Authentic Photoblog Flavour


Go Back   Pixelpost Forum > DEVELOPMENT > Template design and Front-End Code

Post Reply
 
Thread Tools
  #1  
Old 02-11-2008, 04:47 AM
EcoSee Offline
pp veteran
 
Join Date: Nov 2007
Posts: 63
Question Verticle Centering With Fluid Template

Has anyone figured out how to make a template where the image is centered both vertically and horizontally in the browser. You have to be able to change the browser size and have it work cross platform. Ideally, with a header on top and a fixed footer on the bottom so that you can have your site look perfect on a small laptop or on a 24 inch desktop monitor. I have yet to solve this one, though I have been close multiple times.

Last edited by EcoSee; 02-11-2008 at 05:22 AM. Reason: Still Trying....
Reply With Quote
  #2  
Old 02-11-2008, 08:31 AM
xact Offline
pp regular
 
Join Date: Oct 2007
Posts: 46
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
  <title>Universal vertical center with CSS</title>
  <style>
    .greenBorder {border: 1px solid green;} /* just borders to see it */
  </style>
</head>

<body>
  <div class="greenBorder" style="display: table; height: 400px; #position: relative; overflow: hidden;">
    <div style=" #position: absolute; #top: 50%;display: table-cell; vertical-align: middle;">
      <div class="greenBorder" style=" #position: relative; #top: -50%">
        any text<br>
        any height<br>
        any content, for example generated from DB<br>
        everything is vertically centered
      </div>
    </div>
  </div>
</body>
</html>
The solution might be "top:50%" but you might want to add some javascript like top=screen height - (image height /2).
Reply With Quote
  #3  
Old 02-11-2008, 09:14 AM
EcoSee Offline
pp veteran
 
Join Date: Nov 2007
Posts: 63
Need Fluid alignment

That's a fixed solution... but not fluid. Try resizing your browser... it just stays fixed in that one spot. I can get the image to move fluidly up and down just like we all do side to side. But it won't work in IE.
Reply With Quote
  #4  
Old 02-11-2008, 12:09 PM
fredxeric's Avatar
fredxeric Offline
pixelpost guru
 
Join Date: Sep 2006
Location: Montréal, Québec, Canada
Posts: 407
Send a message via AIM to fredxeric Send a message via MSN to fredxeric
try this...

html
Code:
<div id="global" style="width:<IMAGE_WIDTH>px; height:<IMAGE_HEIGHT>px; margin-top:-<IMAGE_HALF_HEIGHT>px; margin-left: -<IMAGE_HLAF_WIDTH>px; "></div>

CSS
Code:
#body {
margin: 0; /* to avoid margins */
text-align: center; /* to correct the centering IE bug */
}

#global {
position: absolute;
left: 50%;
top: 50%;
text-align: left; /* to realign your text */
border: 3px dotted red; /* just to see the block */
}
You will also need to create an addon to get the <IMAGE_HALF_WIDTH> and <IMAGE_HALF_HEIGHT>

PHP
Code:
<?php

$addon_version = "1.0";
	$addon_name = "IMAGE_HALF_WIDTH AND IMAGE_HALF_HEIGHT";
$addon_description  =   "This addon will create 2 news tags, <IMAGE_HALF_WIDTH> & <IMAGE_HALF_HEIGHT>";


/* half_size */
$image_half_width = $image_width / 2;
$tpl = str_replace("<IMAGE_HALF_WIDTH>",$image_half_width,$tpl);

$image_half_height = $image_height / 2;
$tpl = str_replace("<IMAGE_HALF_HEIGHT>",$image_half_height,$tpl);


?>
This will work under multiple various of browser.....

good luck

P.S. I found only one bug with this centering code, it's when you have an image bigger that the screen size the top of the image overflow on the top... well you can try by your self...
Reply With Quote
  #5  
Old 02-11-2008, 07:07 PM
EcoSee Offline
pp veteran
 
Join Date: Nov 2007
Posts: 63
thanks...

I think the <IMAGE_HALF_HEIGHT> addon tag will solve my issue. I have a template designed that should work now in all browsers. Vertical centering is very difficult for cross browser support as we all know that IE Microsucks makes ours lives difficult. I will finish the design and post it for testing and downloading. Thanks!
Reply With Quote
Post Reply


Thread Tools




All times are GMT. The time now is 12:07 PM.

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd. | Style Design: d3 designs