In many projects, the function of grid display needs to be realized. There is a gray dividing line in the middle, but not on both sides.
As shown in the picture:
According to the general idea, set the width of li, and add style to li label by nth of type (n) {}.
Set the width of each Li to 33.33%, but when we add 1px border, the rightmost content will be squeezed down.
This can be achieved by adding the: before: after pseudo class element to the parent ul. Without occupying the width of li
When three columns are displayed, it is realized by adding: before to ul
CSS
<style> 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; } </style>
HTML
<ul class="mp-list"> <li><a hybrid-link="" href="" title="">Hong Kong</a></li> <li><a hybrid-link="" href="" title="">Macao</a></li> <li><a hybrid-link="" href="" title="">Taiwan</a></li> <li><a hybrid-link="" href="" title="">Bangkok</a></li> <li><a hybrid-link="" href="" title="">Singapore</a></li> <li><a hybrid-link="" href="" title="">Seoul</a></li> <li><a hybrid-link="" href="" title="">Tokyo</a></li> <li><a hybrid-link="" href="" title="">Chejudo</a></li> <li><a hybrid-link="" href="" title="">Ban Phatthaya</a></li> </ul>
When four columns are displayed, add styles to: after, and note that you need to change the position of li's width,. MP list: before.
.mp-list:after { content: ''; position: absolute; width: 10%; left: 75%; height: 100%; border-left: .02rem solid #ddd; border-right: 0; }