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 08-05-2010, 12:35 AM   PM User | #1
craziwolf
New to the CF scene

 
Join Date: Aug 2010
Location: Australia
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
craziwolf is an unknown quantity at this point
Css Vertical align text in <div>

Over the last few years i let my knowledge of html and css slip in to the void and now im trying to figure out how to vertically align my text in a div tag but to no avail!

heres what i have

DIV.FI {
background: #b9bab9;
position: absolute;
text-align: center;
vertical-align:middle;
bottom: 0px;
left: 0px;
width: 100%;
height: 50px;
margin-bottom: 150px;
}


any help is appreciated!
craziwolf is offline   Reply With Quote
Old 08-05-2010, 12:38 AM   PM User | #2
spikeon
New to the CF scene

 
Join Date: Aug 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
spikeon is an unknown quantity at this point
display:table-cell;
vertical-align:middle;

vertical align only works in table cells.

note: it only does what you want in table cells, vertical-align on div's normally sets how it ligns up with text as an inline element, therefore setting the display to table-cell will fix your problem

Last edited by spikeon; 08-05-2010 at 12:40 AM..
spikeon is offline   Reply With Quote
Old 08-05-2010, 12:45 AM   PM User | #3
craziwolf
New to the CF scene

 
Join Date: Aug 2010
Location: Australia
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
craziwolf is an unknown quantity at this point
So a div itself does not have a vertical align function?

thanks anyway ill play with the table
craziwolf is offline   Reply With Quote
Old 08-05-2010, 12:48 AM   PM User | #4
spikeon
New to the CF scene

 
Join Date: Aug 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
spikeon is an unknown quantity at this point
it does, however, it sets how the div is alligned within text as an inline element, for instance, vertical-align: bottom would make the bottom of the image in line with the bottom of the text, whereas middle would make the middle of the image be in line with the middle of the text.

using "display: table-cell;" you trick the div into acting like a td, so vertical align will work.
spikeon is offline   Reply With Quote
Old 08-05-2010, 12:48 AM   PM User | #5
spikeon
New to the CF scene

 
Join Date: Aug 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
spikeon is an unknown quantity at this point
note, you don't have to make a table, just put display:table-cell; in your css for the div

so...
Code:
DIV.FI {
display:table-cell;
background: #b9bab9;
position: absolute;
text-align: center;
vertical-align:middle;
bottom: 0px;
left: 0px;
width: 100%;
height: 50px;
margin-bottom: 150px;
}
spikeon 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 10:28 PM.


Advertisement
Log in to turn off these ads.