使用 css 制作加号

新手上路,请多包涵

我有一个模型,用于制作看起来非常简单的加号。但是,我的 css 技能不是很好。制作圆圈没什么大不了的,但在其中制作加号我似乎无法弄清楚。这是我正在尝试做的。

小样

在此处输入图像描述

这是我目前拥有的

在此处输入图像描述

到目前为止,这是我的代码:

网页格式

<div class=circle></div>

CSS

 .circle {
    border-radius: 50%;
    width: 200px;
    height: 200px;
    background-color: rgb(44,108,128)
}

非常基本的东西,但如果有人知道如何添加加号,你会让我的夜晚变得更加美好!谢谢您的帮助!

原文由 Bitwise 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 733
2 个回答

您可以很好地使用 ::after::before 伪元素:

 .circle {
  border-radius: 50%;
  width: 200px;
  height: 200px;
  background-color: rgb(44, 108, 128);
  position: relative;
}
.circle::after {
  content: " ";
  position: absolute;
  display: block;
  background-color: #fff;
  height: 10px;
  margin-top: -5px;
  top: 50%;
  left: 5px;
  right: 5px;
  z-index: 9;
}
.circle::before {
  content: " ";
  position: absolute;
  display: block;
  background-color: #fff;
  width: 10px;
  margin-left: -5px;
  left: 50%;
  top: 5px;
  bottom: 5px;
  z-index: 9;
}
 <div class="circle"></div>

基于 heightwidth <div> 的 plus 将是响应式的。

原文由 Praveen Kumar Purushothaman 发布,翻译遵循 CC BY-SA 3.0 许可协议

这是一个实际以您选择的字体绘制“+”字符的解决方案。

它使用 flexbox 来实现水平和垂直居中。

 .circle {
border-radius: 50%;
width: 200px;
height: 200px;
background-color: rgb(44,108,128)
}

.circle::before {
  content: "+";
  height:200px;
  width:200px;
  font-size:200px;
  display:flex;
  flex-direction:row;
  align-items:center;
  justify-content:center;
  font-weight:bold;
  font-family:courier;
  color:white;
}
 <div class="circle"></div>

原文由 Andrew Shepherd 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
logo
Stack Overflow 翻译
子站问答
访问
宣传栏