html - 如何使无序列表居中
问题描述
我现在已经尝试了多次,但我不知道如何将我的无序列表放在我的 div 中间。
HTML:
<div id="wrapper">
<div class="container">
<img src="flower.jpg"/>
</div>
<div class="header">
<ul>
<li><a href="default.asp">Home</a></li>
<li><a href="news.asp">News</a></li>
<li><a href="contact.asp">Contact</a></li>
<li><a href="about.asp">About</a></li>
</ul>
</div>
CSS:
#wrapper {
position:absolute;
background-color: white;
width:100%;
height:100%;
top:0px;
left:0px;
}
img {
width: 100%;
height: 100%;
display: block;
}
.header {
width: 100%;
height: 100px;
background-color: green;
}
.header a {
color: black;
text-decoration: none;
margin: 50px;
padding: 10px;
font-size: 40px;
text-align: center;
}
ul {
list-style-type: none;
position: absolute;
}
li {
float: left;
}
我究竟做错了什么?我已经在多个元素中尝试过这些:
- 位置:相对/绝对
- 文本对齐:居中
- 利润
- 填充
- 显示:内联
感谢您的帮助<3
解决方案
您可以更改 ul 元素的样式以匹配以下代码:
ul {
list-style-type: none;
position: absolute;
left: 0;
right: 0;
display: flex;
justify-content: center;
}
推荐阅读
- node.js - 使用 azure DevOps 管道部署 Azure 函数应用
- python - 如何拆分括号内用逗号分隔的字符串
- reactjs - react-stripe-elements v1.1.0 createPaymentMethod 在 react 15.6.2 中不起作用
- facebook-graph-api - Facebook Graph API - 无权发布到群组
- google-analytics - Shopify - 如何在页面加载后加载谷歌分析?
- javascript - 离线创建反应应用程序需要什么?
- node.js - Firebase 未更新到节点 12
- angular - Angular10 中的延迟加载路由
- sql - 如何从下面的 SQL 表中获取结果查询?
- docker - 在 linux 上使用 docker 安装商店软件,并在 503 上出错