您好,欢迎来到知库网。
搜索
您的当前位置:首页html css田字十字,CSS3田字格列表的样式编写

html css田字十字,CSS3田字格列表的样式编写

来源:知库网

在很多项目中,需要实现分格展示的功能,中间有灰色分割线,两侧没有。

如图:

按照一般的思路,设置好li的宽度,通过nth-of-type(n){}的方式给li标签添加样式。

设置每个li 33.33%的宽度,但当我们添加1px边框时,最右边的内容就被挤了下来。

这时可以通过给父级 ul 添加:before :after 伪类元素来实现。而不占用li的width

当显示3列时,通过给ul 添加:before来实现

CSS

ul li{ list-style: none;}

.mp-list{

position: relative;

overflow: hidden;

z-index: 0;

background-color: #fff;

}

.mp-list:before {

content: '';

position: absolute;

width: 33.33%;

left: 33.33%;

height: 100%;

border-left: .02rem solid #ddd;

border-right: .02rem solid #ddd;

}

.mp-list li {

width: 33.33%;

height: 2rem;

line-height: 2rem;

font-size: .28rem;

text-align: center;

border-bottom: .02rem solid #ddd;

margin-bottom: -1px;

float: left;

position: relative;

z-index: 10;

color: #212121;

}

.mp-list li a {

color: #212121;

display: block;

overflow: hidden;

text-overflow: ellipsis;

white-space: nowrap;

font-size: .28rem;

}

HTML

当显示4列时,给:after添加样式,注意需要更改li的width、.mp-list:before的位置。

.mp-list:after {

content: '';

position: absolute;

width: 10%;

left: 75%;

height: 100%;

border-left: .02rem solid #ddd;

border-right: 0;

}

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- zicool.com 版权所有 湘ICP备2023022495号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务