css 十字分割线(含四等分布局)

在这里插入图片描述

核心技术

伪类选择器 含义
li:nth-child(2) 第2个 li
li:nth-child(n) 所有的li
li:nth-child(2n) 所有的第偶数个 li
li:nth-child(2n+1) 所有的第奇数个 li
li:nth-child(-n+5) 前5个 li
li:nth-last-child(-n+5) 最后5个 li
li:nth-child(7n) 选中7的倍数
    border-right: 3px solid white;
    border-top: 3px solid white;
    // 父元素中的偶数个子元素
    &:nth-child(2n) {
   
      border-right: 0 none;
    }
    // 父元素的前两个子元素(即第1和第2个item)
    &:nth-child(-n + 2) {
   
      border-top: 0 none;
    }

完整代码范例

<template>
  <div class="container">
    <div class="item">1</div>
    <div class="item">2</div>
    <div class="item">3</div>
    <div class="item">4</div>
  </div>
</template>

<style lang="scss" scoped>
.container {
     
  border: 3px solid red;
  width: 600px;
  height: 300px;
  margin: 30px;
  display: flex;
  flex-wrap: wrap;
  .item {
     
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
    width: 50%;
    height: 50%;
    background-color: yellow;
    border-right: 3px solid white;
    border-top: 3px solid white;
    // 父元素中的偶数个子元素
    &:nth-child(2n) {
     
      border-right: 0 none;
    }
    // 父元素的前两个子元素(即第1和第2个item)
    &:nth-child(-n + 2) {
     
      border-top: 0 none;
    }
  }
}
</style>

相关推荐

  1. html css 布局layout

    2023-12-08 07:54:05       50 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-08 07:54:05       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-08 07:54:05       106 阅读
  3. 在Django里面运行非项目文件

    2023-12-08 07:54:05       87 阅读
  4. Python语言-面向对象

    2023-12-08 07:54:05       96 阅读

热门阅读

  1. macos安装metal 加速版 pytorch

    2023-12-08 07:54:05       64 阅读
  2. 你知道模拟养成游戏如何开发吗?

    2023-12-08 07:54:05       69 阅读
  3. MLX:苹果发布新的机器学习框架

    2023-12-08 07:54:05       55 阅读
  4. OSPF/Open Shortest Path First

    2023-12-08 07:54:05       57 阅读
  5. SSL安全证书怎么查看证书类型?

    2023-12-08 07:54:05       68 阅读
  6. # 如何在Nginx中配置服务器负载均衡(SLB)

    2023-12-08 07:54:05       60 阅读