html - 在菜单中垂直对齐

标签 html css

我的菜单结构是

 <div id="menu">
  <ul>
     <li><a href="#"><span>Two Words</span></a></li>
     <li><a href="#"><span>Three Words</span></a></li>
     <li><a href="#"><span>Very Long menu item</span></a></li>
     <li><a href="#"><span>Short word</span></a></li>
     <li><a href="#"><span>item5</span></a></li>
     <li><a href="#"><span>item6</span></a></li>
  </ul>
 </div>

菜单的宽度固定为 720 像素,高度固定为 50 像素。我怎样才能使菜单项像这张图片一样? enter image description here

这是我的 CSS

#menu {width:720px; height:50px; }
#menu ul {margin:0px; padding:0px;}
#menu ul li {display:inline; float:left; margin-left:1px;}
#menu ul li a {display:block; width:119px; height:100%;}                
#menu ul li a span {display:inline-block;vertical-align:middle;
background-color:gray; text-align:center; font-size: 14px; width:100%;}

最佳答案

这是一个开端:

#menu {
    border: 1px solid #0000ff;
    padding: 10px;
}

ul li {
    border: 1px solid #ff0000;
    display: table-cell;
    height: 80px;
    margin: 10px 5px;
    text-align: center;
    width: 80px;
    vertical-align: middle;
}

jsfiddle

关于html - 在菜单中垂直对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14766461/

相关文章:

html - html 表单使用多少 cpu 功率?

html - Animate.css 和固定定位

php - 我如何使用 php 动态更改 html div 的宽度?

javascript - 模态关闭按钮不起作用

html - Bootstrap 'align-content-around' 不工作

jquery - 为可拖动元素设置边界

html - *ngFor 中的 ngStyle 不起作用

html - Firefox 图像位置(覆盖)

html - 被嵌套列表移动

javascript - Google map 在世界 50% 以上的区域绘制矩形