html - 如何使用css使div在圆形按钮内居中

标签 html css

我想创建一个带有 x 的按钮,该按钮在圆形边框内居中。如何使 x 在圆圈内垂直和水平居中? 我愿意接受与我提供的代码不同的方式。

非常感谢任何帮助,谢谢

https://codepen.io/glittergirl/pen/xybOzL

#mdiv {
  position: fixed;
  right: 0;
  top: 0;
  margin: 20px;
  border: 2px solid #000;
  border-radius: 16px;
  width: 34px;
  height: 34px;
  -webkit-box-sizing: border-box;
     -moz-box-sizing: border-box;
          box-sizing: border-box;
}

.mdiv {
  height:25px;
  width:3px;
  background-color: #000;
  transform: rotate(45deg);
  -webkit-transform: rotate(45deg); /* Safari and Chrome */
      -ms-transform: rotate(45deg); /* IE 9 */
  Z-index:1;
}

.md {
  height:25px;
  width:3px;
  background-color:#000;
  -webkit-transform: rotate(90deg); /* Safari and Chrome */
      -ms-transform: rotate(90deg); /* IE 9 */
          transform: rotate(90deg);
  Z-index:2;
}

最佳答案

您可以使用 left&top: 50%transform: translate(-50%, -50%)

居中

有关示例,请参阅此代码笔。 https://codepen.io/anon/pen/vVEKbV

关于html - 如何使用css使div在圆形按钮内居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52565598/

相关文章:

css - Span 与 ie6 中的 h1 不一致

html - 将文本相对于其 div 居中

javascript - 对元素中的所有文本应用正则表达式

javascript - 动态地向 html 表添加样式 - 使用 DOM、JS

HTML 电子邮件未显示完整的背景图像高度

css - 悬停在 child 身上,对 parent 没有悬停效果

css - 如果指定了任何类,WooCommerce 产品简短描述将呈现两次

jquery - Pane 打开时如何在 Angular Accordion 标题上设置类?

html - 无法使最大宽度与 Bootstrap 多级下拉菜单一起使用

javascript - 添加 DIV 的内部模态对话框 HTML5