Div height as percent

This is a discussion on "Div height as percent" within the Web Page Design section. This forum, and the thread "Div height as percent are both part of the Design Your Website category.



Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Apr 10th, 2007, 17:40
Up'n'Coming Member
Join Date: Jul 2005
Location: uk
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Div height as percent

I have to centre a gif vertically so I started using some divs. It worked in IE but not Firefox or Morzilla. I know when using percent you need a reference point so I added a body style and set it to 100% which works for IE but does not work in Firefox etc. Can anyone help please as I am getting feed up and there must be a simple solution. The code is:
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>stretch vertical</title>
<link href="css/global.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="stretch01">text here </div>
<div class="stretch02">text here </div>
<div class="stretch03">text here </div>
</body>
</html>
The CSS is:
Code: Select all
body {
 margin: 0px;
 height: 100%;
}
.stretch01 {
 height: 33%;
 width: 90%;
 background-color: #666666;
 color: #FFFFFF;
}
.stretch02 {
 height: 33%;
 width: 90%;
 background-color: #CCCCCC;
 color: #FFFFFF;
}
.stretch03 {
 height: 33%;
 width: 90%;
 background-color: #666666;
 color: #FFFFFF;
}
}
Thanks
Reply With Quote

  #2 (permalink)  
Old Apr 10th, 2007, 18:55
Up'n'Coming Member
Join Date: Jul 2005
Location: uk
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Div height as percent

Have found a good answer using absolute positioning at:http://www.webforumz.com/css-forum/2...ering-divs.htm

Are there downsides to absolute positioning and if so is there another way of doing this.

Cheers
Reply With Quote
  #3 (permalink)  
Old Apr 11th, 2007, 06:53
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Div height as percent

Code: Select all
html, body { height: 100%; }
is what you should be using.
Reply With Quote
  #4 (permalink)  
Old Apr 11th, 2007, 07:48
Up'n'Coming Member
Join Date: Jul 2005
Location: uk
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Div height as percent

Thanks Ryan a simple solution that works, fantastico!
Reply With Quote
  #5 (permalink)  
Old Apr 11th, 2007, 20:05
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Div height as percent

No problem
Reply With Quote
Reply

Tags
div, height, percent

Thread Tools

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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
100% height RZX Developer Web Page Design 11 Mar 29th, 2008 10:23
CSS Div height problem dryjoy Web Page Design 1 Jan 6th, 2008 18:05
How to make a table height equal to the browser height ? subhadip Starting Out 4 Sep 20th, 2007 07:56
100% div height jimz JavaScript Forum 2 Mar 22nd, 2006 00:53


All times are GMT. The time now is 00:27.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43