CSS - Vertical Align Content Inside Floating Div
There are floods of threads pertaining to vertical aligning so I hope i'm not assaulted for asking this
How would I go about vertically align content inside of a floating div with a fixed width and height. This is what I have so far. http://section31.us/temp/gallery/images.htm I obviously would like to have those images vertically aligned, can anyone help? Similar TutorialsEDIT: hmm the embedded image isn't showing for me... here's a link: http://i34.tinypic.com/dh7qr6.jpg Referencing the attached image, any ideas about how to achieve this layout using floats (rather than tables)? The part that's giving me trouble is the bottom-left set of links, that should be aligned to the bottom of the container. Also, the width of the container is not fixed - it shouldn't have width specified at all, and expand to fit it's contents. I'm not worried at all about fonts, borders, padding, colors, etc, just trying to achieve the attached macro concept using CSS, best-practices and w/out tables. This layout is easily achieved using tables; the following markup (using tables) will render and behave as described - regardless of the size of the links, the size of the image, or the length of the description, but obviously I'd like to know how to do this with best practices of floating divs. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="robots" content="noindex, nofollow" /> <title>Title</title> <style type="text/css"> td { vertical-align : top; } td.links { text-align : right; } td.links.bottom { vertical-align : bottom; } td.description { width : 150px; } </style> </head> <body> <table> <tr> <td class="links"> <a href="#">Link</a> <br /> <a href="#">Another Link</a> </td> <td rowspan="2"> <img src="http://static.howstuffworks.com/gif/code-breakers-1.jpg" /> </td> <td class="description" rowspan="2"> <h1>Title</h1> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p> </td> </tr> <tr> <td class="bottom links"> <a href="#">Link</a> <br /> <a href="#">Another Link</a> </td> </tr> </table> </body> </html> TYIA for any suggestions. I have a td with a div inside it and I'm trying to vertically align the text in the div. The Div has a background image so the height of the div is important. For whatever reason vertical-align:middle just wont work. I've tried in both IE and FF and nothing I do seems to work. Here is my code Code: .globalNav, .globalNav td { margin: 0px; padding: 0px; width: 100%; height:28px; border-bottom: 1px solid #94AEC1; border-collapse: collapse; } .globalDiv{ color:#fff; width:100%; height:28px; background:#94AEC1 url(../images/grad_bar.gif); background-color:#94AEC1; margin:0px; padding: 0px 0px 0px 10px; overflow:hidden; } .globalDiv a{ font-size:10pt; color:#fff; } .globalDiv a:link,.globalDiv a:visited{ text-decoration:underline; } .globalDiv a:hover{ text-decoration:none; } Thanks Please look at the carousel at the bottom of this page - www.mts-diesel.com What I would ultimately like to do is have it such that each image is vertically centered in the yellow box? Can this be done w/out use of a table cell? Thanks. Tom Hey, I have been looking EVERYWHERE for a solution and there seems to be none just quite yet. I've searched google and all sorts of help forums... and still zip, nothing. What I want to do is vertically-align the text in this example: http://www.tri-m.com/test.html in the middle of the white space. The problem though is that there is an unknown height of the whitespace because I want it to be that no matter what size you size the window, the content will always be vertically aligned... so I'm pretty stuck on how to do this. I'm needing the solution for this desperatly and I have been searching and trying everything for weeks. If anyone could help that would be VERY VERY apperciated. Thank you sooo much to everyone that tries this out. Once again here is the Example: http://www.tri-m.com/test.html Here is my code: Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Tri-M Systems INC.</title> <style type="text/css"> * { margin:0; padding:0; } html, body { height:100%; } body { color:#000; } #container-page { background:#fff; width:100%; min-height:100%; /* For Modern Browsers */ height:auto !important; /* For Modern Browsers */ height:100%; /* For IE */ position:relative; text-align:left; margin:0 auto; } #container-head { background:#fff; } #header { background-color:#0000FF; min-width:830px; width:expression(document.body.clientWidth < 832 ? "830px" : "auto" ); height:81px; position:relative; } #container-content { min-width:830px; width:expression(document.body.clientWidth < 832 ? "830px" : "auto" ); text-align:center; position:relative; padding: 0 0 162px 0; } #container-content:after { height:0; clear:both; display:block; content:"."; visibility:hidden; } #content-sec ul,#content-sec ul li { list-style: none none; } #container-foot { background-color:#ff0000; width:100%; min-width:830px; width:expression(document.body.clientWidth < 832 ? "830px" : "auto" ); height:162px; position:absolute; bottom:0 !important; bottom:-1px; /* For Certain IE widths */ } #foot { height:162px; } </style> </head> <body> <div id="container-page"> <div id="container-head"> <div id="header"> </div><!-- END "header" --> </div><!-- END "container-head" --> <div id="container-content"> <center> <div id="box">VERTICAL ALIGN THIS IN WHITE SPACE</div> <!-- END "box" --> </center> </div><!-- END "container-content" --> <div id="container-foot"> <div id="foot"> </div><!-- END "foot" --> </div><!-- END "container-foot" --> </div><!-- END "container-page" --> </body> </html> - Jacenta Hi, Does anyone know how to veritcally align text using CSS? like <tr valign='middle'> when using tables. My page is on: http://www.3003online.com/demos/ecoceylon/v2/ You can see a difference in the "Home - About Us - Products - Contact Us" links when viewing from IE and Mozilla Firefox. Basically, I would like the text to be centered vertically in the bar... but CSS by default puts it on top. I tried adding padding,which helped in IE... but Firefox still shows the links a bit higher than they should be.,... any ideas how to fix this? Also, a different problem in case anyone knows how to fix it... you can see a small brown bar on the top bar. It is 50px in height. But I have no idea how to make its width as wide as the remainder of the page (this would change with different resolutions). The main content of the page is 760px wide. I would like a brown box next to that, which is 50px in height and the remainder width. Any ideas? "width: auto;" doesn't work unfortunately [ this is a follow up to my previous thread http://forums.devshed.com/showthread.php?t=270438 Any help would be greatly appreciated. Thanks very much. Hi again could someone help me figure out why my left and right box's on thid design are not inline with the content (middle) box thanks see attached pic to see what i mean. Code: CSS CODE body { background:#ffffff; color:#000000; font:76% Verdana,Tahoma,Arial,sans-serif; margin:0; padding:0; text-align:center; } /*** Main container ***/ #container { background:#EAEAEA url() repeat-x; color:#000000; width:90%; margin:5px; min-width:770px; padding:0; } /*** Content ***/ #content { background-color:#EEEEEE; border:1px solid #DEDEDE; color:#000000; padding:15px 20px 5px; height:500px; margin:5px; } /*** Main Banner ***/ #Banner { background-color:#EEEEEE; height:55px; border:1px solid #DEDEDE; padding:15px 20px 5px; margin:5px; } /*** Left Side Navigation ***/ #SideNav { width:15%; float:left; background-color:#EEEEEE; border:1px solid #DEDEDE; color:#000000; min-width:200px; padding:15px 20px 5px; margin:3px; } /*** Right Side content ***/ #RightCon { float:right; width:15%; background-color:#EEEEEE; border:1px solid #DEDEDE; color:#000000; padding:15px 20px 5px; min-width:200px; margin:3px; } Thanks How can i make #mydiv DIV (the main layout div), be vertically aligned to middle? http://www.dinal.ru/new/max/index2.htm I've read a lot of docs about vertical alignment in internet, but I haven't found a good cross-browser solution, which doesnt't destroy my current layout. Thank you in advance Artashes Hi I want to know if it is possible to vertical align the text in these div tags and how it's done. Code: <!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> <style type="text/css" media="all"> #1 {width:15%} #2 {width:20%} #3 {width:25%} #4 {width:20%} #5 {width:20%} #1,#2,#3,#4,#5 { float:left; overflow:hidden; display:inline-block; height:128px; text-align:center; } </style> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <div id="1"><a href="#"><img name="" src="" width="100" height="125" alt="" /></a></div> <div id="2"><a href="#">fffffffffffggfgf fg gd</a></div> <div id="3"><a href="#"> dfg dfg dg d</a></div> <div id="4"><a href="#"> dgd gd d</a></div> <div id="5"><a href="#"> gdf gdg ddg</a></div> </body> </html> Greets, dabomb_gent I'm trying to put a line of text on the bottom of a box. Code: <div style="width:500px;height:500px;background:black;vertical-align:bottom;"> This is a black box </div> <div style="width:500px;height:500px;background:black;vertical-align:baseline;"> This is a black box </div> What the above code displays: Code: ------------------------- | This is a black box | | | | | | | | | | | | | | | ------------------------- What I want it to display: Code: ------------------------- | | | | | | | | | | | | | | | This is a black box | ------------------------- Is not working for me, or I'm not using it right. Here is my problem: http://www.kingtoad.net/development/kingtoad.net/ I want the "navigation" to align to the top even with the "content". I can't seem to get it up there though. Any suggestions would be nice. for example if there is a container div which holds an inner div, if i want the content of the inner div to appear exactly at the bottom edge of the inner div i have used the following code, #outer{ position: relative; float: left; width: 900px; height: 200px; } #outer .inner{ position: relative; float: left; width: 500px; height: 200px; vertical-align: bottom; } however the content of the inner div is starting at its default location which is top left of the inner div instead of using margin-top or padding-top, or positioning methods for the inner div to position the content at the bottom edge can the vertical-align: bottom; be used as this will be very accurate placed at the bottom edge even if the content increases the content will always appear at the bottom edge, unlike other methods where the margin-top, padding-top, and positioning, these values will have to be changed whenever content increases or decreases. please advice. thanks. What I'm trying to do... I have some navigation links, a few pictures, and someone's name on the left hand side of the page. I want everything except for the name to be at the top.... the name is to be at the bottom. Is there a specific way to accomplish this? The content area will generally extend as high as 600 or so px, so would like the name to appear at the very bottom lined up with the content box. Thanks. Not sure exactly what code you need to see, but here's the left hand column: CSS: Code: body {width:770px; height:100%; } .nav_links {vertical-align:top; width:150px; } .nav_links a{display:block; border-top:1px solid black; text-decoration:none;} HTML: Code: <!-- Left Nav Menu --> <div class="nav_links"> Link 1 Link 2 Link 3 Link 4 Link 5 </div> <!-- End Left Nav Menu --> <!-- Misc. Pictures (Left Column)--> <div> <div style="float:right;"> <img src="images/left_pic_1.jpg" alt="Pic1" style="width:50px; margin-bottom:10px;" /><br /> <img src="images/left_pic_2.jpg" alt="Pic2" style="width:50px;" /> </div> </div> <div style="clear:both;"> <div style="float:right;"> <img src="images/left_pic_3.jpg" alt="Pic3" style=" width:50px; margin-bottom:10px;" /><br /> <img src="images/left_pic_4.jpg" alt="Pic4" style="width:50px;" /> </div> </div> <!-- End Misc. Pictures (Left Column) --> <!-- Name --> <div class="name" style="vertical-align:bottom;"> First M. Last </div> <!-- End Name --> Hi, I am trying to use the vertical-align property to make some text appear in the middle of a div (set float:left). However it is not working. Following is some sample code I have done for testing: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>ccc</title> <style> div{ width:16.7em; height:6.8em; border:1px solid black; vertical-align:middle; float:left; } </style> </head> <body> <div>hello</div> </body> </html> Is this possible? Thanks and Regards, Sim085 Hello to all of you, I am doing my first steps in respect to CSS programming and wonder if I can get some hint here. I have created a table, with two different line colors, and a changing line background color with hover. Basically everything works as expected - just the vertical-align command does not respond at all. Am I doing something wrong? What could be the reason, and how can I continue investigating? I am using the CSS stylesheet, in connection with a Joomla 1.5 CMS. Please see the code below: Code: table.general { text-align: left; vertical-align: top; width: 100%; border-collapse: collapse; } table.general th { text-align: center; font-size: 15px; color: white; font-style:bold; height: 30px; background-color:#95B3D7; border: 3px solid #FFFFFF; } table.general tr.row1 { background-color: #f1f1f1; } table.general tr.row2 { background-color: #e0e0e0; } table.general tr.row1:hover { background-color: #CCCCCC; } table.general tr.row2:hover { background-color: #CCCCCC; } table.general td { border: 3px solid #FFFFFF; padding: 4px; } The classes are being used in the following form: Code: <table style="width: 320px;" class="general"> <col span="4" width="80"></col> <tbody> <tr> <th>head A</th> <th>head B</th> <th>head C</th> <th>Alface</th> </tr> <tr class="row1"> <td>Topic A</td> <td>65</td> <td>215</td> <td>35</td> </tr> <tr class="row2"> <td>Topic B</td> <td>2</td> <td>2,3</td> <td>1,2</td> </tr> <tr class="row1"> <td>Topic C</td> <td>68</td> <td>55</td> <td>13</td> </tr> <tr class="row2"> <td>Topic D</td> <td>44</td> <td>50</td> <td>33</td> </tr> <tr class="row1"> <td>etc.</td> <td>494</td> <td>611</td> <td>238</td> </tr> </tbody> </table> Thank you in advance for your kindness! Hi. So I'm trying to get the image div to vertical-align against the text div, within a wrapper div. It currently works fine in Firefox and IE8, but in IE7 and below it displays wrong. I tried to make it work on IE using some workarounds I found but I managed to make it worse. Can anyone help me adapt this code so it works on both firefox AND IE6+ ? Much appreciated! Thanks! Code (since I can't link to it...): Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Test</title> <style type="text/css"> div { border: solid 1px black; } .wrapper { padding: 10px; display: table; } .image { width: 100px; vertical-align: middle; display: table-cell; } .text { margin-left: 100px; padding-left: 10px; display: table-cell; } </style> </head> <body> <div class="wrapper"> <div class="image"> <img src="" alt="Test Image"> </div> <div class="text"> Foo bar Foo bar Foo bar Foo bar Foo bar<br> Foo bar Foo bar Foo bar Foo bar Foo bar<br> Foo bar Foo bar Foo bar Foo bar Foo bar<br> Foo bar Foo bar Foo bar Foo bar Foo bar<br> Foo bar Foo bar Foo bar Foo bar Foo bar<br> </div> </div> </body> </html> Hi, i'm making a site, and want the links in my navigation bar to be centered hoizontally and vertically. the vertical align centering doen't work. does anyone have an idea how to fix it..? the site: http://www.jarra.nl/_TEST/test4.htm the css file: http://www.jarra.nl/_TEST/test4.css oh, and if you notice any problems by viewing this page in other browsers than ie6, please let me know as well. thanks a lot, jarra I know a lot of people have made posts about vertical aligning but nearly all were involving text. I'm trying to vertically align a small image, but every time i do it within the img tag it screws up the adjacent text on IE and only IE. I know it has to do with how vertical align is supposed to be used, specific blocks or inline or something. How would I go about vertically aligning that small arrow image on the top properly. http://chics.onivertneb.com/align.htm Thanks for taking the time to read my question. I have an image that I want to place in the middle of a contaier. I have <center></center> around the <img /> tag, but I can't get it to center vertically with the css below. What am I doing wrong? Thanks, Brad CSS: Code: img.contentimg { vertical-align: middle; } HTML: Code: <div class="textbox1"><center><img class="contentimg" src="images/house1.jpg" /></center></div> Okay, I have an unordered list of images (im usings lists for ajax reasons). I have formatted the list to look much like a 4x4 table. Each cell has an image in it. I need to make the images vertical-align middle. at the moment the code i have is this: Code: <ul style="margin:0;padding:0;list-style-type:none;"> <li style="text-align: center; width: 140px; background-color: #e7e7e7; height: 150px;float: left;"><div style="height: 150px;"><a href="#"><img src="image.gif" style="vertical-align: middle;" ></a></div></li> <li style="text-align: center; width: 140px; background-color: #e7e7e7; height: 150px;float: left;"><div style="height: 150px;"><a href="#"><img src="image.gif" style="vertical-align: middle;" ></a></div></li> <li style="text-align: center; width: 140px; background-color: #e7e7e7; height: 150px;float: left;"><div style="height: 150px;"><a href="#"><img src="image.gif" style="vertical-align: middle;" ></a></div></li> <li style="text-align: center; width: 140px; background-color: #e7e7e7; height: 150px;float: left;"><div style="height: 150px;"><a href="#"><img src="image.gif" style="vertical-align: middle;" ></a></div></li> </ul> I added the div in hopes that this would help the vertical align, however it still aligns at top. Any ideas? I MUST use the list. Thanks for any help! I have a div with this ID: #sml_image_container { margin: 2px; padding: 2px; height: 70px; width: 70px; border: 1px dashed #333333; font-family: Arial, Helvetica, sans-serif; font-size: 10px; color: #FFFFFF; font-weight: bold; vertical-align: middle; } I'd like to have a div work like a cell in a table that is 70px by 70px - with the text centered both horiz. and vert.. But I can't get it. Is the above the correct use of the "vertical-align"? I need the CSS equivilent to <td align="center" valign="middle"> in a DIV. |