告诉我如何创建某个类,并将其分配给这个类,<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>
这就是原始图像的样子(放大 5 倍并增亮 150%):
基于此,得出以下结论:
十字由两条旋转线组成。
要旋转,您可以使用该功能
rotate
线条本身可以制成常规元素或伪元素:只需指定宽度和高度。
接下来,只需确定元素的背景即可。
对于中心的正确位置,值得添加
position:absolute
最后它可能看起来像这样: