CSS - Vertical Aligning To Middle Multiple Lines Of Text.
Normally when I want to vertically align some text to the middle of a div I use
line-height: 40px; and vertical-align: middle; However that only seems to work on single lines of text because with multiple lines of text the line height of each line means there is a large gap between the text rather than centreing the whole lot vertically. How do I get around this? I thought something like the following would work but it doesn't. <div style="line-height: 60px; vertical-align: middle;"> <span style="line-height: normal;">line1<br />line 2</span></div> Similar TutorialsHi Guys, I'm trying to align some text along an image. The problem is, I want two lines of text to the right of the image, aligned to the top. If I put a <BR> tag between the two lines, the second line gets placed below the image. Here's what I have so far. img.top {vertical-align:text-top;} <a href="http://company.com/graphics/thumb.jpg"> <img class="top" src="http://company.com/graphics/thumb.jpg"> </a> <a href="company.com">sample text</a> <a href="company.com">second line</a> Any ideas? I've tried like every switch for the vertical-align property... How do you go about vertically aligning text in a <div> tag that is 200px in height? Here is my development site: http://www.pursuedbybear.com/sunwashed/ Is there any way to vertically center the links in the left hand nav inside their orange boxes without resorting to a table? I've tried vertical-align: middle and padding-top the #nav ul li a element, but neither works. I've done some searching here and the results haven't been encouraging - anyone have something different I could try? I mean really, this isn't exactly a super-complicated or obscure thing I'm trying to do, you'd think CSS could handle it. Any advice? hi is there a way to get a div to be in the vertical middle of the screen. i tried : margin-top: auto; margin-bottom: auto; but it doesn't work. thanks I'm working on a new page at http://www.plumeriawebdesign.com/webdevgirl/ and am having problems aligning the middle div column. In IE it shows approximately 25px below the dark blue date bar while it shows correctly in FF. I'm also having problems with it extending further than the 100% wrapper div. Here is my HTML Code: <body> <div id="wrapper"> <div id="top" align="center"><img src="images/webdev_02.gif" alt="Exceptional web design made affordable"/></div> <div id="nav"> <?php $today = date("D M d Y"); echo "$today\n"; ?> </div> <div id="left">left column</div> <div id="right">right column</div> <div id="middle">middle column</div> </div> </body> CSS is he Code: /* CSS Document */ html { height: 100%; } body { margin: 0px 0px 0px 0px; background-color:#333; padding:0px; font:11px verdana, arial, helvetica, sans-serif; position: relative; min-width: 600px; width: 100%; height: 100%; color: #333; } #wrapper { width: 100%; height: 100%; } html>body #wrapper { height: 100%; } #left { float: left; left:0px; top:113px; width:12%; background-color: #a2cde3; border-right: 2px solid #333; padding: 5px 5px; } #middle { top: 0px; voice-family: "\"}\""; voice-family: inherit; margin-left: 12%; margin-right:12%; padding: 5px 5px; height: 100%; min-width: 360px; width: 76%; background-color: #626262; color: #000; } html>body #middle { margin-left: 12%; margin-right:12%; } #right { float: right; top: 0; width:12%; background-color: #a2cde3; border-left: 2px solid #333; padding: 5px 5px; } #top { min-width: 600px; width: 100%; height: 100px; background-color: #FFF; color: #FFF; voice-family: "\"}\""; voice-family: inherit; } html>body #top { height:100px; } #nav { top: 100px; left: 0; min-width: 600px; width: 100%; height: 12px; background-color: #005698; color: #e4e4e4; vertical-align: bottom; text-align:left; text-indent: 5px; clear: both; } I've got an image that is 75px high. Right beside it, I have a H1. I want to vertically align the H1 in the middle of the image. Vertical align doesn't work, and for some reason, setting the line height to the height of the image doesn't work either. 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> hmmm, i can't make this work...the text goes to the top, not the middle... #mrtop { height: 33px; width: auto; vertical-align: middle; } both "title" and "subtitle" are just text attributes, nothing more... <div id="mrtop"><span class="title"><? echo $a ?></span> <span class="subtitle"><? echo $q ?></span></div> i would use padding at the top and bottom but i'm concerned about text zooming...if people were to use text zoom and it needed more space for the "mrtop" div it would screw up some other stuff on the page (so i need to make "middle" work if it's possible)... thanks for any advice...v The problem that I am having stems from attempted compatability for 1. IE/other browsers, and 2. Not scrolling or having an absurd amount of dead space on different resolutions. Given that I'm currently using a 16:9 laptop, anything that I make for my resolution is very likely to scroll vertically on anything else. I would like to preface this by saying that, while I am a young person and am .. relatively web savvy, I'm also pretty miserable at CSS. I'll pick it up whenever I need to use it, but these times generally end up being a year plus apart, and so I generally .. forget everything that I picked up the last time, and have to re-learn. I am very good at nesting tables, and using an absurd number of them to get things to look how I want, but .. I really want to get away from that. CSS is cleaner and less .. well, less flat out dumb than using seven tables in one page to align things the way you want them? The Actual Problem I Have: (Do ignore the hideously coloured background, the green/blue combo is temporary until I get the code working properly. Anyway, so apparently I can't post URLs so: clocktock.com is the website in question, code on it is Code: <html> <head> <link rel="stylesheet" type="text/css" href="poing.css"> <link rel="icon" type="image/png" href="img/RL16.png"/> <title>[ eroding.net ]</title></head> <body> <table cellspacing="0" cellpadding="0" class="main" height="100%" width="100%" valign="bottom"><tr><td width=100% align=center valign="bottom"> <table border="0" cellspacing="0" cellpadding="0" height="90%"> <tr><td background="img/top_left.png" width=14 height=39></td> <td background="img/top.png" width=622 height=39><img src="img/top_left2.png" border=0></td> <td background="img/top_right.png" width=14 height=39></tr></td> <tr><td background="img/left.png" width=14 height=1></td> <td bgcolor="black" width="700" height="800" border=0 cellspacing=0 cellpadding=0 background="img/table_bg_grunge.png" valign="top"> <br><br> <center> aaa <br><br> </center> </td><td background="img/right.png" width=14></tr></td></table> </tr></td></table> </body></html> CSS Code: body { font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Tahoma, Arial; background-color: #0F0F0F; color: #424242; background: url(img/damask.png); background-attachment: fixed; background-repeat: repeat; margin-bottom: 0px; vertical-align: bottom;} table { color: #424242; font: 11px Tahoma, Arial; margin: 0px; } sm {font-size: 0.9em; } a:link { color: #424242; } a:visited { color: #595959; } a:hover { color: #424242; text-decoration:none; } a:active { color: #424242; } What I would, ideally, like to have is for the box to take a percentage of space. Say, vertically 80 or 90%, and then a blank remainder on the top. Horizontally, say, 10 or 15% on either side and then 70 or 80% for the "box." But, google as I might, I just can't find the right CSS commands to do it. It just gets funny looking and shrinks all my border images (Though I erased the code that caused that). I have an image and to the right of it I have text. I want the text to be aligned veritcally to the middle of the image. I can do the following and it works: Code: .icon {vertical-align: middle;} <a href="index.php"><img src="images/icon.png" class="icon" border="0" /></a> Header Goes Here However, if I wrap H1 tags around "Header Goes Here" the text drops below the image. Any ideas on how to use header tags and have it aligned? I know I could make the icon as a background with H1 but I want it to be clickable. Is there any way to make it so the H1 Hi there, I'm trying to display paragraph with a table embedded in there inline. I hope the table can behave like a big letter in the paragraph, with the line aligned in the center of the table. For example, if I want to make "1/2" to a vertical "1 <hr/> 2", I would put it in a table and change the "display" property as follows: Code: <p> This is a long paragraph. This is a long paragraph. This is a long paragraph. This is a long paragraph. This is a long paragraph. This is a long paragraph. I HAVE <table style="display:inline;vertical-align:middle"> <tr> <td> 1 <hr /> 2 </td> </tr> </table> PIZZA. This is a long paragraph. This is a long paragraph. This is a long paragraph. This is a long paragraph. This works perfectly for me on IE, but on Firefox only the "inline" property works, and the "vertical-align" property doesn't (i.e., the table and the line text are aligned at the bottom still). Did I do something wrong? Or is this a Firefox bug? Thanks Anyone knows of a method to cause a vertical line to come all the way down ? Currently it stops where the text stops. but i want it to go all the way to the buttom of the document regardless of the text. (right now i use box border on one side) Thanks! Hi everyone! i have this mockup in fireworks for my personal site.. problem is... i cant put it together the way i like it using CSS here is my mockup and the slices ive made... http://www[dot]phpugph[dot]com/talk/index.php?action=dlattach;topic=8005.0;attach=1720;image im sorry for the link... i cant seem to post a proper one do u guys know how i should go about it? the middle column should be fixed width but the right and left column should be fluid thanx It seems that whenever I create a dashed/dotted, verticle line in CSS and view it in IE6, and scroll, the line gets all blurred and messed up. Does anyone know about this and if there is a way to fix this? I'm going through hell trying to make a site look the same in IE and Firefox. The biggest problem is the gaping spaces IE adds between elements. What is the best way to fix this? Example at patrolmag.com/new. Any advice or help would be most appreciated. P.S. How the page looks in Firefox 3 is ideal. I just need to make at least IE7 come somewhere close to matching it. Hi: After entering data into a database from a form (HTML) using php, I now have to retrieve the data, place it in a form style and print. Everything works fine when I do the print except for one thing. Description of Problem: When I print using IE 6.0, all vertical and horizontal lines which separate data from each other (cells) print. When I do the print in Mozilla, only the horizontal lines appear. How can I fix this, or, what makes it do this in Mozilla and not in IE? There is one thing I'm not doing, I'm not using CSS to format the form. Could this fix the problem? Any suggestions will be greatly appreciated! Thanks! A number of years ago I created a web site for a mattress store where I worked (7 days a week, for 5 years). The point is this: I'm not a great web designer. The code is ancient and the owner wants me to bring the thing up to date. Using tables, I had a system for creating thin, vertical lines that went up and down the entire heighth of the page. The lines divided the content area from the borders in a neat way - although, again, using very old HTML. It looks like this: http://www.wholesalewarehouseinc.com What I'd found was that if I used a fixed-sized header and some tables I could produces the thin line that you see on that page. This was the basic code: Code: <table width=100% height=100% cellpadding=0 cellspacing=0 topmargin=0 leftmargin=0 rightmargin=0> <td background="http://www.wholesalewarehouseinc.com/lf.gif" width=50% align=left><td width="1" background="dot.png"> <img src="dot.png"></td> </td><td valign=top> <table cellpadding=0 cellspacing=0 border=0 rightmargin=0 leftmargin=0 bottommargin=0> <img src="logo.png"></td> <td background="http://www.wholesalewarehouseinc.com/lf.gif" width=100% align=left><td width="1" background="dot.png"> <img src="dot.png"></td> </table> My question is this, and maybe this is too general for a meaningful answer. Is there a way to do the same sort of thing with CSS? ive searched google throughout and im blank on how to do this Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled</title> <style type="text/css"> * { margin:0; padding:0; } div { width:70%; margin:0 auto; height:20em; border:.4em solid black; } p { border:.4em solid black; margin:0 auto; line-height:8em; display:inline; width:55%; height:8em; } span { display:block; color:red; font-size:2em; width:60%; margin:0 auto; text-align:center; } </style> </head> <body> <div> <p> <span>X</span> </p> </div> </body> </html> I need the outer box to be vertiacllly aligned within the viewport, the other boxes vertically aligned within each other. does that make sense? I thought u could do it with line-height but i can't get it working. fresh eyes? Edit: New code there. I'm attempting to vertically align my content to the size of the browser window, something that I've concluded can be done a million ways after days of Googling and reading. My outcome seems to work fine in all browsers (FF, Safari, Opera, Chrome, Navigator are the ones I've tested) except Internet Explorer. It renders perfect in IE 8, but there is a huge margin bumping the content down in all other versions of IE. The complete execution can be seen he http://www dot kristenshemanski dot com/testing/index dot html Any thoughts/input is welcome. I've completely hit a wall with this one. Also, I am indeed still using nested tables. I still have not completely mastered div tables, so I've decided to stick with the familiar until I learn a bit more. This project has really opened my eyes to how out-dated my coding is. Here is my CSS for the vertical positoning: Code: /* Divs */ #outer { position: absolute; height: 100%; width: 100%; border:0; overflow: visible; vertical-align: middle; } #inner { position: relative; top: 50%; height: 645px; width: 100%; margin: 0px auto; } I am having problems with vertical aligning both texts and images. Can someone show me a working example or tell me where I messed up the codes below? http://efetuncel.win.aplus.net/ryt/new/ Code: #rcontent{ float:right; width:490px; padding:0px; } #rcontent .category{ float:left; width:240px; height:120px; margin:30px 0px 0px 5px; background: url(images/bg_home_category.gif) } #rcontent .category img{ float:left; vertical-align:middle; } <div id="rcontent"> <div class="category"> <img src="images/home_categories_gb.gif" alt="" /> </div> <div class="category"> </div> <div class="category"> </div> <div class="category"> </div> </div> |