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)
When using the MySQL database, if you have not lo...
Why do I want to organize the content in this area...
Download the image (optional step, if omitted, it...
pt-heartbeat When the database is replicated betw...
<br />Most of the time when we talk about na...
Table of contents Preface🌟 1. API Introduction 2....
Permission denied: The reason for this is: there ...
<br />The content is reproduced from the Int...
Table of contents 1. The writing order of a compl...
Preface The default database file of the MySQL da...
CSS combination selectors include various combina...
Table of contents 1. Dep 2. Understand obverser 3...
1. Basic implementation of limit In general, the ...
Building web pages that comply with Web standards ...
Table of contents Overview What is Big O notation...