RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1593500
Accepted
BlackStar1991
BlackStar1991
Asked:2024-09-11 03:42:07 +0000 UTC2024-09-11 03:42:07 +0000 UTC 2024-09-11 03:42:07 +0000 UTC

CSS 通过伪元素创建图标

  • 772

告诉我如何创建某个类,并将其分配给这个类,<div>您可以获得与此类似的图像。

图标

我有原版空白。

body{
  margin: 0;
  background-color: #090C09;
}


.gr {
  width: 60px;
  height: 60px;
  
  
  position: relative;
  box-sizing: border-box;
  border: 2px solid #000;
  outline: 1px solid rgba(30, 32, 29, 0.4);
  outline-offset: 3px;
  background-image: linear-gradient(#0e130f 2px, transparent 2px),
  linear-gradient(90deg, #0e130f 2px, transparent 2px);
  background-size: 2px 2px;
  background-color: #0B100A;


  box-shadow: inset 0 0 40px 0 rgba(0, 0, 0, 0.9);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
<div class="gr"></div>

但我不明白如何用CSS来实现这个“十字”。也许有人可以展示?最好是通过:before :after

/// 添加了一个 SVG 示例

body{
  margin: 0;
  background-color: #090C09;
}


.gr {
width: 60px;
height: 60px;
position: relative;
box-sizing: border-box;
border: 2px solid #000;
outline: 1px solid rgba(30, 32, 29, 0.4);
outline-offset: 3px;
background-image: 
  linear-gradient(#0e130f 2px, transparent 2px),
  linear-gradient(90deg, #0e130f 2px, transparent 2px);
background-size: 60px 60px;
background-color: #0B100A;
box-shadow: inset 0 0 40px 0 rgba(0, 0, 0, 0.9);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
  }
  
  .gr_new:after{
content:"";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
background-image:  url('data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 60 60%22 style=%22enable-background:new 0 0 60 60%22 xml:space=%22preserve%22%3E%3Cstyle%3E.st1,.st2%7Bfill:none;stroke-miterlimit:10%7D.st1%7Bstroke:%23283028;stroke-width:4%7D.st2%7Bstroke:%23000%7D%3C/style%3E%3Cg%3E%3Cpath class=%22st1%22 d=%22m0 0 60 60M0 61 60 0%22/%3E%3Cpath class=%22st2%22 d=%22m1.5-1.5 29 29M29.5 32.5l29 29M-1.5 1.5l29 29M32.5 29.5l29 29M-1.5 59.5l29-29M1.5 62.5l29-30M32.6 30.1 61.5 1.5M30.5 27.5l28-29%22/%3E%3C/g%3E%3C/svg%3E');
}
<div class="gr gr_new"></div>

css
  • 2 2 个回答
  • 54 Views

2 个回答

  • Voted
  1. Best Answer
    UModeL
    2024-09-12T02:30:11Z2024-09-12T02:30:11Z

    这就是原始图像的样子(放大 5 倍并增亮 150%):

    在此输入图像描述

    基于此,得出以下结论:

    .gr {
      /* Масштаб --> */ font-size: 16px;
      position: relative;
      width: 23.25em; height: 23.25em;
      background-color: #272f24;
      box-shadow: inset 0 0 0.1875em 1.3125em #1a1f19, inset 0 0 0.875em 1.875em #000, inset 0 0 7.5em 5.625em #0b1009;
      /* Раскомментировать и настроить filter: brightness(.3); */
    }
    .gr::before {
      content: '';
      position: absolute;
      inset: 0;
      background: center / 21.875em 21.875em linear-gradient(45deg, #0000 calc(50% - 0.75em), #262d24 calc(50% - 0.375em) calc(50% + 0.375em), #0000 calc(50% + 0.75em)) no-repeat, center / 21.875em 21.875em linear-gradient(-45deg, #0000 calc(50% - 0.75em), #262d24 calc(50% - 0.375em) calc(50% + 0.375em), #0000 calc(50% + 0.75em)) no-repeat, center / 20.5em 20.5em linear-gradient(45deg, #0000 calc(50% - 1.5em), #0008 calc(50% - 0.875em) calc(50% + 0.875em), #0000 calc(50% + 1.5em)) no-repeat, center / 20.5em 20.5em linear-gradient(-45deg, #0000 calc(50% - 1.5em), #0008 calc(50% - 0.875em) calc(50% + 0.875em), #0000 calc(50% + 1.5em)) no-repeat;
      --mask: center / 22.5em 22.5em radial-gradient(circle, #000f 14.375em, #0000 15.3125em) no-repeat;
      -webkit-mask: var(--mask); mask: var(--mask);
      /* Дополнительное размытие filter: blur(0.125em); */
    }
    
    body { background-color: #090C09; }
    <div class="gr"></div>

    • 3
  2. Grundy
    2024-09-11T04:56:10Z2024-09-11T04:56:10Z

    十字由两条旋转线组成。

    要旋转,您可以使用该功能rotate

    线条本身可以制成常规元素或伪元素:只需指定宽度和高度。

    接下来,只需确定元素的背景即可。

    对于中心的正确位置,值得添加position:absolute

    最后它可能看起来像这样:

    body {
      margin: 0;
      background-color: #090C09;
    }
    
    .gr {
      width: 60px;
      height: 60px;
      position: relative;
      box-sizing: border-box;
      border: 2px solid #000;
      outline: 1px solid rgba(30, 32, 29, 0.4);
      outline-offset: 3px;
      background-image: linear-gradient(#0e130f 2px, transparent 2px), linear-gradient(90deg, #0e130f 2px, transparent 2px);
      background-size: 2px 2px;
      background-color: #0B100A;
      box-shadow: inset 0 0 40px 0 rgba(0, 0, 0, 0.9);
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
    }
    
    .gr::before,
    .gr::after {
      content: '';
      background: red;
      height: 1px;
      width: 100%;
      position: absolute;
    }
    
    .gr::before {
      transform: rotate(-45deg);
    }
    
    .gr::after {
      transform: rotate(45deg);
    }
    
    
    }
    <div class="gr"></div>

    • 0

相关问题

  • 几何形状的阴影

  • 如何制作这样的人物组合?

  • 如何在css中制作一个图形

  • 如何制作阴影(投影)渐变

  • 网格项目传输不起作用

  • 更改屏幕宽度时换行。引导程序

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5