html - 在圆圈内垂直居中加号

标签 html css

我试图将加号在圆圈内垂直和水平居中。我试过使用 line-height,但这似乎不起作用:

代码

.circle {
  font-size: 3.27rem;
  font-weight: 400;
  width: 94px;
  border-radius: 50%;
  color: white;
  line-height: 94px;
  text-align: center;
  padding: 0;
  height: 94px;
  margin: 0 auto;
  box-shadow: 0px 2px 5px rgba(94, 94, 94, 0.68);
  cursor: pointer;
  background: #fcce00;
  position: absolute;
  right: 50px;
  z-index: 10;
  span {
    line-height: 94px;
  }
}
<div class="circle">
  <span>+</span>
</div>

最佳答案

尽管您的代码似乎可以按照您的意愿工作(在 FF 中测试),但您需要将 span 从 CSS 中的 .circle 中取出,因为这不是预处理器 CSS,因此不是有效的 CSS。

片段:

.circle {
  font-size: 3.27rem;
  font-weight: 400;
  width: 94px;
  border-radius: 50%;
  color: white;
  line-height: 94px;
  text-align: center;
  padding: 0;
  height: 94px;
  margin: 0 auto;
  box-shadow: 0px 2px 5px rgba(94, 94, 94, 0.68);
  cursor: pointer;
  background: #fcce00;
  position: absolute;
  right: 50px;
  z-index: 10;
}
span {
  line-height: 94px;
}
<div class="circle">
  <span>+</span>
</div>

关于html - 在圆圈内垂直居中加号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35051693/

相关文章:

html - Z-索引/溢出问题?

html - Mac OS X命令行终端下sed的使用

javascript - 按下键时如何使输入自动添加文本?

jquery - 如何使用 jQuery 在输入的 keyup 上从特定的 div 添加/删除类?

css - 如何制作两个带有文本的内联 div 完美的正方形

html - 元素之间自动增长div

html - 容器不能在大屏幕的容器流体内工作

css - 当子图像绝对定位时,DIV 背景消失

forms - 图像上的表单字段

HTML 表格行背景颜色与 float 属性不符合预期