首先先看设计稿

图中的12345便是主角进度条。

分析需求如下:
线的长度不固定,适应移动端和pc端
点平均地分布在一条线上
点的个数不固定,可能会改变
激活的点之间线的颜色是绿色的

两种种方式 百分比宽度切分和flex布局

贴上代码
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div class="pub-wrap">
<div class="pub-title" id="pubTitle">在群内累计布置3天作业,即可加入先锋教师!</div>
<ul class="pub-process process-5" id="pubProcess">
<li class="active"><span class="ball">1天</span></li>
<li class="active"><span class="ball">1天</span></li>
<li><span class="ball">1天</span></li>
<li><span class="ball">1天</span></li>
<li><span class="ball">1天</span></li>
</ul>
</div> <!-- flex版本 -->
<div class="pub-wrap">
<div class="pub-title" id="pubTitle">在群内累计布置3天作业,即可加入先锋教师!</div>
<ul class="pub-process process-5 pub-process-flex" id="pubProcess">
<li class="active"><span class="ball">1天</span></li>
<li class="active"><span class="ball">1天</span></li>
<li><span class="ball">1天</span></li>
<li><span class="ball">1天</span></li>
<li><span class="ball">1天</span></li>
</ul>
</div>
</body>
</html>

css

ul {
margin:0;
padding:0;
}
li {
list-style: none;
} .pub-wrap {
position: relative;
padding: 0 30px 10px;
margin-top: 28px;
border-radius: 6px;
background-color: #edf2f2;
} .pub-title {
padding-top: 14px;
margin-right: -20px;
margin-left: -20px;
font-size: 1.1875rem;
text-align: center;
} .pub-process {
position: relative;
height: 35px;
margin-top: 28px;
margin-left: 35px;
font-size: 0;
color: #fff;
} .pub-process:after {
position: absolute;
top: 50%;
left: 0;
z-index: 1;
width: 99%;
height: 4px;
content: "";
-webkit-transform: translate(0, -50%);
transform: translate(0, -50%);
background-color: #d9d9d9;
} .pub-process li {
position: relative;
z-index: 5;
display: inline-block;
width: 25%;
height: 35px;
font-size: .875rem;
} .pub-process li:first-child {
width: 35px;
margin-left: -35px;
} .pub-process .ball {
position: absolute;
top: 0;
right: 0;
z-index: 7;
width: 35px;
height: 35px;
line-height: 35px;
content: "";
text-align: center;
border-radius: 50%;
background-color: #d9d9d9;
} .pub-process .active .ball {
background-color: #11c2c2;
} .pub-process .active + .active:after {
position: absolute;
top: 50%;
left: 0;
z-index: 6;
width: 100%;
height: 4px;
content: "";
-webkit-transform: translate(0, -50%);
transform: translate(0, -50%);
background-color: #11c2c2;
} .process-3 li {
width: 50%;
} .process-5 li {
width: 25%;
} /* flex ver */
.pub-process-flex {
display: -webkit-box;
}
.pub-process-flex li {
display: list-item;
-webkit-box-flex: 1;
width: auto;
}
.pub-process-flex li:first-child {
width: 35px;
margin-left: -35px;
-webkit-box-flex: 0;
}

实现效果如图

使用百分比因为宽度是百分比设死的,这样在点的数量修改时,我们还是要改css,所以建议使用flex布局更完美。

最新文章

  1. Ember.js实现单页面应用程序
  2. 配置无线网络的时候会提示“Enter Password for Default Keyring to Unlock”
  3. Visual Studio 调试技巧
  4. Cassandra1.2文档学习(12)—— hint机制
  5. RPi 2B 中文语言包
  6. JS调用PHP 和 PHP调用JS的方法举例
  7. Asp.Net Mvc - 在OnResultExecut* 拦截Action返回的HTML
  8. Python Set集合,函数,深入拷贝,浅入拷贝,文件处理
  9. hdu 5126 stars cdq分治套cdq分治+树状数组
  10. Eclipse和PyDev搭建python开发环境
  11. C++与AS3
  12. Kafka 协议实现中的内存优化
  13. [linux]ngrep命令、常见用法
  14. 一些爬虫中的snippet
  15. js跨域解决方案
  16. Sharepoint Solution Gallery Active Solution时激活按钮灰色不可用的解决方法
  17. SENG201 (Software Engineering I) Project
  18. v-charts 第一次亲密接触
  19. Kali 2.0 下 Metasploit 初始化配置
  20. Android Studio在项目中添加assets资源目录

热门文章

  1. foreach 改变集合时不能使用
  2. Web端网站兼容性测试如何进行?来看看浏览器的兼容性测试要点
  3. tp5 webupload文件上传至七牛云
  4. nginx lua模块常用的指令
  5. 使用history.back()返回此网页需要使用您之前输入的数据才能正常显示
  6. 机器学习之主成分分析(PCA)
  7. VuePress 博客之 SEO 优化(五)添加 JSON-LD 数据
  8. Nginx高并发实现原理以及常用的优化手段
  9. centos7使用chrony同步阿里云时间
  10. Linux移植总结--uboot从不同介质上启动分析