html - 按钮在 css 中没有显示为圆形

标签 html css button

我正在尝试使用 CSS 创建一组圆形按钮:

.button {
display:inline;
height:10px;
width:10px;
border: 1px solid black;
border-radius:50%;
}

但是,我的按钮看起来更像卵形,如下面的屏幕截图所示。为什么会这样,我该如何解决这个问题?

enter image description here

最佳答案

这是因为默认情况下 <button>元素有 padding .设置padding: 0;

.button {
  display:inline;
  height:10px;
  width:10px;
  border: 1px solid black;
  border-radius:50%;

  padding: 0;
}
<button class="button"></button>

在谷歌浏览器中,按钮的默认填充是 padding: 2px 6px 3px;这意味着

padding-top: 2px;
padding-right: 6px;
padding-bottom: 3px;
padding-left: 6px;

这就是使它看起来呈卵形的原因。所以 padding不必为零,但您必须将所有值设置为相同大小:

.button {
  display:inline;
  height:10px;
  width:10px;
  border: 1px solid black;
  border-radius:50%;

  padding: 20px;
}
<button class="button"></button>

关于html - 按钮在 css 中没有显示为圆形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43434178/

相关文章:

css - 十六进制颜色计算器 : change color for twitter bootstrap buttons

JavaScript 没有将结果值设置到 <p> 的 innerHTML 中

html - 如何为选择框的下拉设置高度

javascript - 动画图标不会在切换单击时占据其原始位置

php - 如何为每个表制作 html?

ruby-on-rails - 提交按钮文本来自哪里(Ruby on rails)?

php - 两个图像按钮或两个提交

PHP 视频上传不将值存储在 DB 和 DIR 中

javascript - React 和 CSS 动画

html - 居中任何大小的内容并仍然允许滚动