参见英文答案 >
How to center an element horizontally and vertically?10个答案我创建一个新的网站,我需要知道的东西(将显示为例)。
说我这样做:
HTML;
<div id="center-in-bar"> <ul> <li>content..</li> <li>content..</li> <li>content..</li> <li>content..</li> </div>
和css:
#center-in-bar { list-style:none; display:inline-block; /*what to do to make all the li elements centered both horizontal and vertical? in the center-in-bar element*/ }
我要做什么来使所有的li元素都以水平和垂直为中心?在中心的元素?
任何帮助将被贴上:))
解决方法
尝试这个CSS片段:
#center-in-bar ul { ... text-align:center; /* center horizontally */ vertical-align:middle; /* center vertically */ ... } #center-in-bar li { ... display:inline; /* you might want to use this instead of "inline-block" */ ... text-align:center; /* center horizontally */ vertical-align:middle; /* center vertically */ ... }