Results 1 to 4 of 4
Thread: Vertical Center on Div
-
12-14-2008, 09:12 PM #1
- Join Date
- Apr 2008
- Location
- Boston, MA
- Posts
- 13,233
- Thanks
- 745
- Thanked 729 Times in 564 Posts
- Blog Entries
- 4
- Feedback Score
- 4 (100%)
Vertical Center on Div
There are lots of solutions online that claims to center elements (both text and image) vertically inside a div. I found too many ifs to get them working. Some requires known element height etc etc. This one solution from vdotmedia.com seem to really work. Works to center a div in the middle of the page as well as works to place elements (text, image etc) at vertical center of the div.
So here is the modified version of the code:
Code:<html> <head> <style type="text/css"> /*change the height: 500px; below to height: 100%; to get the div centered vertically to the page; you would also need body html {height:100%;} to get that working.*/ #container { width: 100%; height: 500px; display: table; } #position { display: table-cell; vertical-align: middle; width: 100%; text-align: center; } /*IE does not understand vertical-align:middle. to get it working on IE we have this conditional css*/ <!--[if IE]> #container { position: relative; } #position { position: absolute; top: 50%; } #content { position: relative; top: -50%; } <![endif]--> </style> </head> <body> <div id="container"> <div id="position"> <div id="content"> <img src="test.jpg" height="25" alt="" /> </div> </div> </div> </body> </html>Free Classified Ads & BUSINESS/PROFESSIONAL SOCIAL NETWORK
-
12-14-2008, 10:13 PM #2
- Join Date
- Apr 2008
- Location
- Boston, MA
- Posts
- 13,233
- Thanks
- 745
- Thanked 729 Times in 564 Posts
- Blog Entries
- 4
- Feedback Score
- 4 (100%)
ok I have to take part of the credit back. It does not seem to work with DOCTYPE XHTML
there need some extra work to get it working.
separate the main css and the conditional part on two files. then use a condition to load corresponding css.
Or you can put the main css on a file and after the line that loads the file, put the conditional part; inside <head></head> tags.Free Classified Ads & BUSINESS/PROFESSIONAL SOCIAL NETWORK
-
12-15-2008, 10:11 PM #3
Master
- Join Date
- Dec 2008
- Posts
- 1,099
- Thanks
- 51
- Thanked 34 Times in 27 Posts
- Feedback Score
- 0
Ahh I see, thanks a lot Manik. You have excellent CSS knowledge
-
12-16-2008, 09:36 AM #4
Hey site is good but i am kind of lost the site navigation is bad lol
Similar Threads
-
Google executive hired by Facebook for data center management
By mamedesign in forum GoogleReplies: 5Last Post: 04-27-2010, 10:35 PM -
Google Data Center Multiple IP Address SEO Research Tool
By BrainPulse in forum GoogleReplies: 3Last Post: 05-21-2009, 05:08 AM -
Windows 7 Touch Control Makes Media Center More Awesome
By krates98 in forum MicrosoftReplies: 15Last Post: 12-24-2008, 04:11 PM -
Call Center Call
By KahneFan in forum General TalkReplies: 4Last Post: 12-15-2008, 10:42 PM -
Partners wanted for Call Center business
By enam in forum Joint VenturesReplies: 6Last Post: 06-24-2008, 05:01 AM



Reply With Quote

