html - 标题 li 元素不会并排对齐

标签 html css

我试图并排对齐标题中的 li 元素。但是,当我用内联显示和左浮动定义 ul 和 li 时,我试图实现的目标并没有发生,而 li 元素仍然垂直堆叠而不是水平并排?

* {
    margin: 0;
    padding: 0;
    width: 100%;
    margin: 0;
    list-style: none;
    text-decoration: none;
    font-size: 1em;
    font-family: Helvetica Neue, Helvetica,Arial,Sans-serif;
}
a {
    background: transparent;
    border: none;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    transition: .3s color;
    transition: .3s height;
}
header {
    display: block;
    position: fixed;
    height: 80px;
    width: 100%;
}
.header-wrapper {
    width: 100%;
    height: 100%;
    background: transparent;
}
.header-bg,
.header-content {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    text-align: center;
}
.header-bg {
    color: gray;
    background: white;
    border-bottom: 1px solid black;
    transition: .3s height;
    height: 0;
}
.header-content {
    transition: .3s color;
    color: white;
    background: transparent;
    height: 80px;
    transition: .3s height;
    overflow: hidden;
    list-style: none;
}
ul {
       list-style-type: none;
       margin: 0;
       padding: 0;
}
li {
display: inline-block;
float:left;
}
.navBarLinks {
    color: inherit;
    cursor: pointer;
    font-size: .8em;
    letter-spacing: 0.05em;
    transition: .3s color;
}
content {
    display: block;
    height: 2000px;
    background: orange;
}
.stage {
    color: #fff;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    -ms-flex-pack: center;
    justify-content: center;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    height: 100vh;
    background: white;
    border-bottom: 1px solid black;
    font-size: 48px;
    height: 200px;
    width: 100%;
}
.stage-0 {
    background: grey;
    height: 400px;
}
<header>
  <div class="header-wrapper">
    <div class="header-bg"></div>
    <div class="header-content">
      <ul id="horizontal-list">
        <li class="instagram"> <a href="" class="navBarLinks">Social Icon</a></li>
        <li class="home"><a href="" class="navBarLinks">Logo </a></li>
        <li class="hamburger"><a href="" class="navBarLinks">Hamburger</a></li>
      </ul>
    </div>
  </div>
</header>
<content>
<div class="stage stage-0">1</div>
<div class="stage stage-2">3</div>
<div class="stage stage-4">5</div>
<div class="stage stage-6">7</div>
<div class="stage stage-8">9</div>
<div class="stage stage-10">11</div>
<div class="stage stage-12">13</div>
<div class="stage stage-14">15</div>
<div class="stage stage-16">17</div>
<div class="stage stage-18">19</div>
<div class="stage stage-20">21</div>
<div class="stage stage-22">23</div>
</content>

最佳答案

您的列表项因此垂直堆叠:

* {
    margin: 0;
    padding: 0;
    width: 100%; /*right here*/
    margin: 0;
    list-style: none;
    text-decoration: none;
    font-size: 1em;
    font-family: Helvetica Neue, Helvetica,Arial,Sans-serif;
}

每个列表项 - everything for that matter - 宽度为 100%,因此它们被迫堆叠。考虑将 width:100%; 放在类上或以其他方式定位元素可能更为谨慎。 * 通常用于默认样式的绝对重置。

关于html - 标题 li 元素不会并排对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34732841/

相关文章:

CSS float 不插入相邻元素

html - 使用 bootstrap 4 flexbox 垂直对齐多行

html - 具有不继承内联显示的下拉菜单的内联样式菜单

javascript - 从麦克风获取音频数据作为数组

javascript - 从 URL 获取外部页面的源 DOM/HTML

jquery - 我如何读取任何单击元素的 css 属性?

javascript - 我的代码播放器上的 CSS 部分不工作

Html 大小太长 - Bing 站长工具

javascript - 如何在用户滚动到页面底部时启动 jQuery 事件?

css - WordPress主题删除元素外的文本