html - 添加边框导致我的标题格式出现问题

标签 html css html-lists border

我正在尝试为页眉添加边框,但当我这样做时,行高(或类似的东西)变得困惑。

HTML -

<div class='header'>
  <ul>
    <li>Home</li>
    <li>Services</li>
    <li>Estimates</li>
    <li>Co2 Calculator</li>
    <li>Contact Us</li>
  </ul>
</div> 


CSS -

.header {
    background-color: #006633;
    height: 50px;
    border-radius: 5px;
    border: 1px solid gray;
}

ul.headerlist {
    line-height: 50px;
    float: left;
    list-style-type: none;
    width: 19%;
    text-align: center;
    color: white;
}

与使用<ul>有关吗?或 <li>

最佳答案

首先清理您的 HTML 结构。

  1. 您不需要将类应用到所有 LI,因为它们都是 一样。
  2. 改为将 .header 的 CSS block 应用于 ul
  3. 使用测量 ul 高度的 line-height 来获取 li 垂直居中。

.header {
  /* do whatever you want with the header */
  width: 100%; /* Adjust as needed */
  height: auto;
  }

.header ul {
background-color: #006633;
height: 50px;
border-radius: 5px;
border: 1px solid gray;
  display: block;
}
.header li {
width: 19%;
text-align: center;
color: white;
    display: inline-block;
  vertical-align: middle;
    line-height: 50px;
}
<div class=header>
    <ul>
                    <li>Home</li>
                    <li>Services</li>
                    <li>Estimates</li>
                    <li>Co2 Calculator</li>
                    <li>Contact Us</li>
    </ul>
 </div>

关于html - 添加边框导致我的标题格式出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28229399/

相关文章:

html - 如何在 td rowspan 行中设置无边框

html - 显示带有内联图像的单选按钮的验证消息

javascript - 使用 jQuery 和固定步数的线性动画

CSS选择ul中的所有li

html - 禁用跨度悬停

javascript - Bootstrap 多选 : Adding images instead of text

javascript - 使用 jQuery 添加/删除 css 类以通过 css 类识别元素

html - 行内 block 元素之间的空白

html - 是否有使用现代 css 样式更改输入元素中信号灯粗细的解决方案?

html - 内容下方的 Wordpress 侧边栏