How to write the style of CSS3 Tianzi grid list

How to write the style of CSS3 Tianzi grid list

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)

Recommend

Linux MySQL root password forgotten solution

When using the MySQL database, if you have not lo...

Docker installation steps for Redmine

Download the image (optional step, if omitted, it...

Detailed explanation of using pt-heartbeat to monitor MySQL replication delay

pt-heartbeat When the database is replicated betw...

Navigation Design and Information Architecture

<br />Most of the time when we talk about na...

Usage and best practice guide for watch in Vue3

Table of contents Preface🌟 1. API Introduction 2....

Detailed explanation of the solution to permission denied in Linux

Permission denied: The reason for this is: there ...

Web Design Help: Web Font Size Data Reference

<br />The content is reproduced from the Int...

How to change the database data storage directory in MySQL

Preface The default database file of the MySQL da...

This article teaches you how to play with CSS combination selectors

CSS combination selectors include various combina...

Implement a simple data response system

Table of contents 1. Dep 2. Understand obverser 3...

MySQL uses limit to implement paging example method

1. Basic implementation of limit In general, the ...

Don't forget to close the HTML tag

Building web pages that comply with Web standards ...

How to Learn Algorithmic Complexity with JavaScript

Table of contents Overview What is Big O notation...