Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-22-2006, 03:45 AM   PM User | #1
xxkylexx
New Coder

 
Join Date: Apr 2006
Posts: 50
Thanks: 2
Thanked 0 Times in 0 Posts
xxkylexx is an unknown quantity at this point
Vertical Alignment Problems (within a div)

Hey guys,

Having a problem here with vertically aligning images and text within a <div>. I have a loop that is running to display a users thumbnailed images within their gallery on my image hosting site. However, not all thumbnails are the same height, causing it to look stagard within each row. So my solution to make it look "nicer" would be to vertically align the contents of each <div> centered.

I know the first thing your going to say is use <div style="vertical-align:middle">, but I have tried this and it isn't working, which I do not understand. Also, looping <td>'s would be insufficient since they won't break down to another row when space runs out on the current row. They would just keep going out into one single row.

My code is pasted below of the entire section that is being looped (loop begins within the {{section}} tags). Any helps/tips would be helpful.

Code:
{{* ---A loop for each thumbnail---- *}}
<table width="100%">
	<tr>
		<td align="center" valign="top">
		{{section name=id loop=$image_name}}
		<div style="float: left; width: 126px; height: 150px; vertical-align:middle ">
			<a href="javascript:image_details_popup('details.php?name={{$image_name[id]}}', 700, 400)"><img src="images/{{$username}}/-{{$image_name[id]}}.png" style="border:1px solid #000000; " /></a><br />
			<small>{{$image_name[id]}}<br />
			{{$time_uploaded[id]}}</small>
		</div>
		{{/section}}
		</td>
	</tr>
</table>


Thanks!
Kyle

Last edited by xxkylexx; 04-22-2006 at 03:48 AM..
xxkylexx is offline   Reply With Quote
Old 04-22-2006, 04:32 AM   PM User | #2
Kravvitz
Senior Coder

 
Join Date: Feb 2006
Location: USA
Posts: 1,013
Thanks: 0
Thanked 0 Times in 0 Posts
Kravvitz is an unknown quantity at this point
vertical-align only works like valign when used in tables.

Set the line-height of those <div>s to the same as their height.
__________________
Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
Java != JavaScript && JScript != JavaScript
Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.
Kravvitz is offline   Reply With Quote
Old 04-22-2006, 04:49 AM   PM User | #3
Arbitrator
Senior Coder

 
Arbitrator's Avatar
 
Join Date: Mar 2006
Location: Splendora, Texas, United States of America
Posts: 2,887
Thanks: 5
Thanked 186 Times in 183 Posts
Arbitrator is on a distinguished road
You can vertically align content in a page division using the following CSS attributes:

<div style="display: table-cell; vertical-align: middle;"></div>

This doesn't work in MSIE however.
__________________
Please for the love of god stop making IE. You current "browser"s cause me to cry every day. —Phil *
Arbitrator is offline   Reply With Quote
Old 04-22-2006, 04:59 AM   PM User | #4
xxkylexx
New Coder

 
Join Date: Apr 2006
Posts: 50
Thanks: 2
Thanked 0 Times in 0 Posts
xxkylexx is an unknown quantity at this point
I tried this and it diddn't seem to work either. (I use Firefox)


any other ideas?



Thanks!!
xxkylexx is offline   Reply With Quote
Old 04-22-2006, 05:09 AM   PM User | #5
Arbitrator
Senior Coder

 
Arbitrator's Avatar
 
Join Date: Mar 2006
Location: Splendora, Texas, United States of America
Posts: 2,887
Thanks: 5
Thanked 186 Times in 183 Posts
Arbitrator is on a distinguished road
I just tested that code in Firefox 1.5.0.2 to make sure and it does indeed work. Your box needs to be bigger than the content for it to have any effect however; this means that your height property needs to be specified and set to a size taller than the content for it to work.
__________________
Please for the love of god stop making IE. You current "browser"s cause me to cry every day. —Phil *
Arbitrator is offline   Reply With Quote
Old 04-22-2006, 05:32 AM   PM User | #6
Kravvitz
Senior Coder

 
Join Date: Feb 2006
Location: USA
Posts: 1,013
Thanks: 0
Thanked 0 Times in 0 Posts
Kravvitz is an unknown quantity at this point
Oops. Sorry. It won't work because you have text under the image.

Try this.
__________________
Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
Java != JavaScript && JScript != JavaScript
Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.
Kravvitz is offline   Reply With Quote
Old 04-22-2006, 05:44 AM   PM User | #7
Arbitrator
Senior Coder

 
Arbitrator's Avatar
 
Join Date: Mar 2006
Location: Splendora, Texas, United States of America
Posts: 2,887
Thanks: 5
Thanked 186 Times in 183 Posts
Arbitrator is on a distinguished road
Just to note, if you use Kravvitz' code you may want to use a conditional comment to issue commands to MSIE instead of the star-html hack since they're fixing that hack in IE7.
__________________
Please for the love of god stop making IE. You current "browser"s cause me to cry every day. —Phil *
Arbitrator is offline   Reply With Quote
Old 04-22-2006, 06:13 AM   PM User | #8
xxkylexx
New Coder

 
Join Date: Apr 2006
Posts: 50
Thanks: 2
Thanked 0 Times in 0 Posts
xxkylexx is an unknown quantity at this point
Quote:
Originally Posted by Kravvitz
Oops. Sorry. It won't work because you have text under the image.

Try this.

Yea, I think that is what is causing the problems.
xxkylexx is offline   Reply With Quote
Old 04-22-2006, 06:27 AM   PM User | #9
Kravvitz
Senior Coder

 
Join Date: Feb 2006
Location: USA
Posts: 1,013
Thanks: 0
Thanked 0 Times in 0 Posts
Kravvitz is an unknown quantity at this point
Quote:
Originally Posted by Arbitrator
Just to note, if you use Kravvitz' code you may want to use a conditional comment to issue commands to MSIE instead of the star-html hack since they're fixing that hack in IE7.
You don't have to. The comment before the doctype on that page puts IE6-7 in backwards compatibility mode (aka quirks mode). In backwards compatiblity mode IE7 support the star html hack; in Standards mode it doesn't.
__________________
Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
Java != JavaScript && JScript != JavaScript
Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.
Kravvitz is offline   Reply With Quote
Old 04-22-2006, 06:33 AM   PM User | #10
xxkylexx
New Coder

 
Join Date: Apr 2006
Posts: 50
Thanks: 2
Thanked 0 Times in 0 Posts
xxkylexx is an unknown quantity at this point
Great. Solution is here: http://www.jakpsatweb.cz/css/css-ver...-solution.html
xxkylexx is offline   Reply With Quote
Old 04-22-2006, 06:35 AM   PM User | #11
Arbitrator
Senior Coder

 
Arbitrator's Avatar
 
Join Date: Mar 2006
Location: Splendora, Texas, United States of America
Posts: 2,887
Thanks: 5
Thanked 186 Times in 183 Posts
Arbitrator is on a distinguished road
Quote:
Originally Posted by Kravvitz
You don't have to. The comment before the doctype on that page puts IE6-7 in backwards compatibility mode (aka quirks mode). In backwards compatiblity mode IE7 support the star html hack; in Standards mode it doesn't.
Ah, interesting bit of information; didn't know that.

That is assuming that he wants to display his web page in quirks mode though which in and of itself can cause browser-compatibility problems.

Quote:
Originally Posted by Kravvitz
Yup, already been there. Uses more hacks though.
__________________
Please for the love of god stop making IE. You current "browser"s cause me to cry every day. —Phil *

Last edited by Arbitrator; 04-22-2006 at 06:37 AM..
Arbitrator is offline   Reply With Quote
Old 04-22-2006, 07:18 AM   PM User | #12
xxkylexx
New Coder

 
Join Date: Apr 2006
Posts: 50
Thanks: 2
Thanked 0 Times in 0 Posts
xxkylexx is an unknown quantity at this point
Any idea why I am getting this in IE only? Works great with other browsers.




Code used:
Code:
{{* ---A loop for each thumbnail---- *}}
<table width="100%">
	<tr>
		<td align="center" valign="top">
		{{section name=id loop=$image_name}}
		<div id="outer">
			<div id="middle">
				<div id="inner">
					<a href="javascript:image_details_popup('details.php?name={{$image_name[id]}}', 675, 450)"><img src="images/{{$username}}/-{{$image_name[id]}}.png" style="border:1px solid #000000 " /></a><br />
					<small>{{$image_name[id]}}<br />
					{{$time_uploaded[id]}}</small>
				</div>
			</div>
		</div>
		{{/section}}
		</td>
	</tr>
</table>

CSS bit:
Code:
/* ~~~Start Vert Align of Div's~~~ */

#outer{
	float: left;
	width: 120px;
	height: 150px;
	overflow: hidden;
	position: relative;
	border: 1px dashed #d0dbe9;
	}
	
#outer[id]{
	display: table;
	position: static;
	}

#middle{
	position: absolute;
	top: 50%;
	} /* for explorer only*/
	
#middle[id]{
	display: table-cell;
	vertical-align: middle;
	position: static;
	}

#inner{
	position: relative;
	top: -50%
	} /* for explorer only */

#inner[id]{
	position: static;
	text-align: center;
	}

/* ~~~End Vert Align of Div's~~~ */



Thanks, yet again.
xxkylexx is offline   Reply With Quote
Old 04-22-2006, 09:17 AM   PM User | #13
Kravvitz
Senior Coder

 
Join Date: Feb 2006
Location: USA
Posts: 1,013
Thanks: 0
Thanked 0 Times in 0 Posts
Kravvitz is an unknown quantity at this point
Try this.
Code:
#middle{
	position: absolute;
	top: 50%;
	left: 50%;
	} /* for explorer only*/
	
#middle[id]{
	display: table-cell;
	vertical-align: middle;
	position: static;
	}

#inner{
	position: relative;
	top: -50%
	left: -50%;
	} /* for explorer only */
__________________
Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
Java != JavaScript && JScript != JavaScript
Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.
Kravvitz is offline   Reply With Quote
Old 04-22-2006, 03:08 PM   PM User | #14
xxkylexx
New Coder

 
Join Date: Apr 2006
Posts: 50
Thanks: 2
Thanked 0 Times in 0 Posts
xxkylexx is an unknown quantity at this point
Thanks for the reply. However, it diddn't seem to work. Any other ideas?
xxkylexx is offline   Reply With Quote
Old 04-22-2006, 11:03 PM   PM User | #15
Kravvitz
Senior Coder

 
Join Date: Feb 2006
Location: USA
Posts: 1,013
Thanks: 0
Thanked 0 Times in 0 Posts
Kravvitz is an unknown quantity at this point
I missed this yesterday, but at the top of your X/HTML code you have a note that says "A loop for each thumbnail", which leads me to believe that you have non-unique IDs which would cause problems.

IDs should be unique. You could use a class instead.

Class and ID Selectors
When should I use a class and when should I use an ID?
__________________
Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
Java != JavaScript && JScript != JavaScript
Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.
Kravvitz is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 05:47 PM.


Advertisement
Log in to turn off these ads.