html - 将 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;
}
解决方案
您可以display:flex
与footer
一起添加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>
推荐阅读
- ruby - id 为 123 的用户没有正确更新 id 为 123 的项目
- python - 为什么 Requests 库无法读取源代码?
- wysiwyg - 如何在 react-quill Hooks 中添加 className="" 和自定义标签?
- java - 如何移动 3d 对象并将其 360 度旋转显示在 Vuforia for android 的跟踪图像顶部?
- javascript - Javascript JSON 解析 php base64(file_get_contents($file)) 响应
- json - 如何处理不同的 JSON 模式并分派 hem 以由正确的解析器处理?
- c++ - constexpr 函数中的非文字(通过 std::is_constant_evaluate)
- javascript - 搜索使用异步存储存储的项目
- .net-core - 为什么在 vs 代码(.NET Core)中调试时不构建 C# 代码?
- flutter - 如何在 Flutter 中像 Youtube 一样显示时间