I come from the world, and have been looking at resources on google about doing multiple wrappers to vertically align content -- however it seems like it's really ugly.
Is there an easier way now with HTML5? Is there some sort of implementation that uses something like the HBox/VBox mentality? I saw there are examples for non-ie browsers -- is there a compliant way?
How the heck does anyone in their right mind do HTML now? It's a mess!
//// EDIT
I've finally figured out how to vertically align an entire box over a screen, how I'm figuring out how to vertically center list items.
I've tried two methods to align this html:
<nav>
<ul>
<li><a href="#!/home">Home</a></li>
<li><a href="#!/link1">Link #1</a></li>
</ul>
</nav>
one using display:inline, the other using float:left (within a container). When using inline, it seems the list items ignore the height: css, and when using float:, the links within the li do not vertically align. Do I need to place div's within the li's to get them to vertically center as well?
Deprecated as an attribute Occasionally you will see “valign” used on table cells to accomplish vertical alignment. e.g. <td valign=top> . It should be noted that this attribute is deprecated and should not be used.
Using the Line-Height Property In most cases, you can also center text vertically in a div by setting the line-height property with a value that is equal to the container element's height. Let's create the same div element with a yellow border around it as above.
Answer: Use the CSS line-height property Suppose you have a div element with the height of 50px and you have placed some link inside the div that you want to align vertically center. The simplest way to do it is — just apply the line-height property with value equal to the height of div which is 50px .
Why don't you try using display: box
with box-align:center
, this is CSS3, so not every browser supports it yet (only Chrome, FireFox, and Safari)
http://www.w3schools.com/cssref/css3_pr_box-align.asp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With