加了浮动的li怎么垂直水平居中,和平均分布?????

老梁啊 2018-11-21 05:16:30
代码如下,,,,

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.tu{
width: 300px;
height: 300px;
background-color: #ccc;
background-repeat: no-repeat;
background-position: center top;
position: relative;
}
.xiaobei{
width: 60px;
height: 10px;
border-radius: 25px;
background-color:rgba(255,255,255,0.4);
position: absolute;
bottom: 20px;
left: 50%;
margin-left: -30px;
}
.xiaobei li{
width: 8px;
height: 8px;
background-color: #f00;
list-style: none;
float: left;
border-radius: 100%;
margin: 1px auto;
}
</style>
</head>
<body>
<div class="tu">
<ul class="xiaobei">
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</body>
</html>
...全文
434 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
老梁啊 2018-11-21
  • 打赏
  • 举报
回复
引用 1 楼 jslang 的回复:

.tu{
width: 300px;
height: 300px;
background-color: #ccc;
background-repeat: no-repeat;
background-position: center top;
position: relative;
}
.xiaobei{
width: 64px;
height: 10px;
border-radius: 25px;
background-color:rgba(255,255,255,0.4);
position: absolute;
bottom: 20px;
left: 50%;
padding: 0;
margin: 0 0 0 -32px;
}
.xiaobei li{
padding: 0;
margin: 1px 4px;
width: 8px;
height: 8px;
background-color: #f00;
list-style: none;
float: left;
border-radius: 100%;
}



float: left;方式做不到真正自动的水平居中,和平均分布,只能用margin人为调整。
要真正自动的水平居中,和平均分布,需要用伸缩盒display:flex
好的谢谢老哥
天际的海浪 2018-11-21
  • 打赏
  • 举报
回复

	.tu{
		width: 300px;
		height: 300px;
		background-color: #ccc;
		background-repeat: no-repeat;
		background-position: center top;
		position: relative;
	}
	.xiaobei{
		width: 64px;
		height: 10px;
		border-radius: 25px;
		background-color:rgba(255,255,255,0.4);
		position: absolute;
		bottom: 20px;
		left: 50%;
		padding: 0;
		margin: 0 0 0 -32px;
	}
	.xiaobei li{
		padding: 0;
		margin: 1px 4px;
		width: 8px;
		height: 8px;
		background-color: #f00;
		list-style: none;
		float: left;
		border-radius: 100%;
	}

float: left;方式做不到真正自动的水平居中,和平均分布,只能用margin人为调整。 要真正自动的水平居中,和平均分布,需要用伸缩盒display:flex

61,112

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧