参见英文答案 >
How to center an element horizontally and vertically?10个
http://jsfiddle.net/UmHNL/2/
http://jsfiddle.net/UmHNL/2/
<div class="container"> <span>Some text,yay</span> </div> <div class="container"> <span>Some text,yay. But shit time,there is alot of text,so we get a problem with breaking lines and the given height :( How can I align vertical now?</span> </div> <style> .container { width: 100%; height: 50px; line-height: 50px; border: 1px solid black; } .container span { padding-left: 30px; } </style>
这个解决方案的效果非常好,直到屏幕宽度太小 – 将我的文本打破了几行.
当我google这个问题,我发现这么多疯狂的过于复杂的解决方案与javascript和div推我的内容到位.任何人可以帮助我做这项工作,而不增加更多的标记?