首页 > 解决方案 > 将 Ul 置于页脚中心

问题描述

我试图在我的页脚上将我的两个列表放在另一个下方,但我做不到。我的内容总是按左右排列,不知道为什么有人有想法?在这里我把测试

https://codepen.io/ta_io/pen/oNNZpyE

footer {
  z-index: 1;
  width: 100%;
  height: auto;
  bottom: 0;
  background-color: orange;
  position: fixed;
}

footer ul {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow: hidden;
  background-color: orange;
  padding: 12px 70px;
}

footer li a {
  display: block;
  padding: 20px 20px;
  background-color: saddlebrown;
  text-decoration: none;
}

footer li {
  float: left;
}
footer li a {
  padding: 20px 20px;
}
footer .menu {
  clear: none;
  float: none;
  max-height: none;
}

footer .menu2 {
  clear: none;
  float: none;
  max-height: none;
}

标签: htmlcssheaderfooter

解决方案


您可以display:flexfooter一起添加justify-content:center

在下面的代码片段中,它们不“适合”在页脚内以保持并排,但在更大的屏幕上,它们会适合。

html {
  height: 100vh;
  margin: 0 auto;
  padding: 0 auto;
  overflow-y: scroll;
  overflow-x: hidden;
}

body {
  height: 100vh;
  margin: 0;
  font-family: Helvetica, sans-serif;
  background-color: #f4f4f4;
  background-color: #dbdbdb;

  text-rendering: optimizeLegibility;
  transition: opacity 0.8s ease 0s;
  -webkit-transition: opacity 0.8s ease 0s;
}

a {
  color: #000;
}
footer {
  z-index: 1;
  width: 100%;
  height: auto;
  bottom: 0;
  background-color: orange;
  position: fixed;
  display:flex;
  align-items:center;
  justify-content:center;
  flex-wrap:wrap;
}

footer ul {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow: hidden;
  background-color: orange;
  padding: 12px 70px;
}

footer li a {
  display: block;
  padding: 20px 20px;
  background-color: saddlebrown;
  text-decoration: none;
}

footer li {
  float: left;
}
footer li a {
  padding: 20px 20px;
}
footer .menu {
  clear: none;
  float: none;
  max-height: none;
}

footer .menu2 {
  clear: none;
  float: none;
  max-height: none;
}


  
 <footer>
        
         
   
            <ul class="menu2" >
    <li><a  style="background-color: red" href="#work">link 1</a></li>
    <li><a style="background-color: red" href="#about">link 2</a></li>
    <li><a style="background-color: red" href="#careers">link 3</a></li>
                <li><a style="background-color: red" href="#careers">link 4</a></li>
  
  </ul>
            
            <ul class="menu">
    <li><a href="#work">FB</a></li>
    <li><a href="#about">TW</a></li>
    <li><a href="#careers">G</a></li>
  
  </ul> 
           
                

        </footer>


推荐阅读