C3选择器 :only-child :first-child :last-child的正确使用

比如ul下不确定li的多少 又是下面连体按钮样式
在这里插入图片描述

 li:only-child

在这里插入图片描述

li:first-child
li:not(:first-child)
li:last-child

在这里插入图片描述

li:first-child
li:not(:first-child)
li:last-child

整体代码如下

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
    ul{
        background: #fff;
        display: flex;
        padding-right: 20px;
        list-style: none;
    }
    li{
        padding: 7px 35px;
        border: 1px solid #ccc;
        font-size: 12px;
        cursor: pointer;
    }
    li:first-child {
        border-radius: 5px 0 0 5px;
        background: #3bafda;
        color: #fff;
    }
    li:last-child {
        border-radius: 0 5px 5px 0;
    }
    li:not(:first-child) {
        border-left: 0;
    }
    li:only-child {
        border-radius: 5px;
    }
    </style>
</head>

<body>
    <ul>
        <li>COSCO</li>
        <li>APL</li>
        <li>SCAC</li>
        <li>APNL</li>
        <li>EFEF</li>
    </ul>
</body>

</html>
发布了17 篇原创文章 · 获赞 0 · 访问量 189

猜你喜欢

转载自blog.csdn.net/who_become_gods/article/details/104628430