In many projects, it is necessary to implement the function of grid display, with a gray dividing line in the middle and none on both sides. As shown in the figure: According to the general idea, set the width of li and add style to the li tag through nth-of-type(n){}. We set each li to a width of 33.33%, but when we add a 1px border, the rightmost content gets pushed down. This can be achieved by adding :before :after pseudo-class elements to the parent ul. Without occupying the width of li When displaying 3 columns, this is achieved 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="">Jeju Island</a></li> <li><a hybrid-link="" href="" title="">Pattaya</a></li> </ul> When 4 columns are displayed, add styles to :after. Note that you need to change the width of li and the position of .mp-list:before. .mp-list:after { content: ''; position: absolute; width: 10%; left: 75%; height: 100%; border-left: .02rem solid #ddd; border-right: 0; } The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. |
<<: The implementation principle of Zabbix dynamic execution monitoring collection script
>>: MySQL string splitting example (string extraction without separator)
Copy code The code is as follows: <!DOCTYPE ht...
Table of contents Listener watch Format Set up th...
Table of contents 1. Write Webshell into outfile ...
The principle of uploading pictures on the front ...
This article uses examples to illustrate the use ...
Core SQL statements MySQL query statement that do...
Table of contents Preface 1. Overview 2. Read-wri...
1. Parent components can pass data to child compo...
A long time ago, I summarized a blog post titled ...
Table of contents Preface Why introduce unit test...
The MySQL database does not have an incremental b...
In the past, when I needed the border length to b...
question CSS fixed positioning position:fixed is ...
<br />In general guestbooks, forums and othe...
Abstract: Analysis of two MySQL SQL statement loc...