首页 前端知识 CSS,设置虚线网格为元素背景

CSS,设置虚线网格为元素背景

2024-09-08 02:09:22 前端知识 前端哥 988 597 我要收藏

CSS,设置虚线网格为元素背景

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>网格背景</title>
  <style>
    body{
      height: 1080px;
      width: 1920px;
      margin: 0;
    }
    /* 虚线部分 */
    .bg-grid::before,
      .bg-grid::after {
        opacity: .5;
        content: '';
        background-repeat: repeat;
        position: absolute;
        width: 100%;
        height: 100%;
        left: 0;
        top: 0;
      }

      .bg-grid::before {
        /* 从左往右 */
        background: linear-gradient(to right, rgba(255, 255, 255, 1) 1px, transparent 1px),
          linear-gradient(to bottom, rgba(0, 0, 0, 0.6) 1px, transparent 1px);
        background-size: 10px 30px;
      }

      .bg-grid::after {
        /* 从上往下 */
        background:
          linear-gradient(to bottom, rgba(255, 255, 255, 1) 1px, transparent 1px),
          linear-gradient(to right, rgba(0, 0, 0, 0.6) 1px, transparent 1px);
        background-size: 30px 10px;
      }

      .bg-grid {
        position: absolute;
        top: 10%;
        left: 50%;
        width: 400px;
        height: 400px;
        z-index: -1;
        border-right: 1px #adaeaf dashed;
        border-bottom: 1px #adaeaf dashed;
      }
   /* 实线条部分 */
   .bg-grid1{
    position: absolute;
    top: 10%;
    left: 20%;
    width: 400px;
    height: 400px;
     background: linear-gradient(to right,#5f5f5f 1px,transparent 1px),
     linear-gradient(to bottom,#5f5f5f 1px,transparent 1px);
     background-size: 20px 20px;
     background-repeat: repeat;
     border-right: 1px #5f5f5f solid;
      border-bottom: 1px #5f5f5f solid;
   }
  </style>
</head>
<body>
 <div class="bg-grid"></div>
 <div class="bg-grid1"></div>
</body>
</html>
效果图

在这里插入图片描述

转载请注明出处或者链接地址:https://www.qianduange.cn//article/17819.html
标签
评论
发布的文章

关于HTML的知识

2024-09-18 23:09:36

js简单实现轮播图效果

2024-09-18 23:09:36

CSS3美化网页元素

2024-09-18 23:09:27

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!