【问题标题】:Create a circular button in BS3在 BS3 中创建一个圆形按钮
【发布时间】:2023-04-11 01:09:01
【问题描述】:

我想在 BS3 中创建一个圆形按钮(一个完美的圆形),中间有一个 fontawesome(4.0) 图标。

到目前为止,我有以下代码:

HTML:

<a href="#" class="btn btn-default"><i class="fa fa-user"></i></a>

为了使这个按钮成为一个完美的圆形,CSS 标记是什么?

【问题讨论】:

标签: css twitter-bootstrap twitter-bootstrap-3


【解决方案1】:

你可以做一些事情,比如添加一个类来添加边框半径

HTML:

<a href="#" class="btn btn-default btn-circle"><i class="fa fa-user"></i></a>

CSS:

.btn-circle {
  width: 30px;
  height: 30px;
  text-align: center;
  padding: 6px 0;
  font-size: 12px;
  line-height: 1.42;
  border-radius: 15px;
}

如果你想改变尺寸,你需要相应地改变字体大小或填充

【讨论】:

  • 可能是一个 css 覆盖了中心规则你最后添加的类吗?
  • 将高宽改为30px
【解决方案2】:

(未跨浏览器测试),但这是我的答案:

.btn-circle {
  width: 40px;
  height: 40px;
  line-height: 40px; /* adjust line height to align vertically*/
  padding:0;
  border-radius: 50%;
}
  • 通过 line-height 属性垂直居中
  • 填充变得无用,必须重置
  • 边框半径与按钮大小无关

【讨论】:

  • border-radius:50% 非常简单。
  • 这应该是公认的答案。与 FontAwesome 完美配合。此外,您应该使用 34px 而不是 40px 以保持与标准 BS3 按钮高度一致。
  • 如果 font-awesome 不能居中,更改 font-size 并添加text-align: center;。默认情况下,Font-awesome 垂直对齐基线,如果字体大小不合适,导致它无法对齐到中心。
【解决方案3】:

如果您已经在本地下载了这些文件,那么您可以在 bootstrap-social.css 中更改以下类,只需添加 border-radius: 50%;

.btn-social-icon.btn-lg{height:45px;width:45px;
   padding-left:0;padding-right:0; border-radius: 50%; }

这里是 HTML

<a class="btn btn-social-icon btn-lg btn-twitter" >
   <i class="fa fa-twitter"></i>
</a>
<a class=" btn btn-social-icon btn-lg btn-facebook">
   <i class="fa fa-facebook sbg-facebook"></i>
</a>
<a class="btn btn-social-icon btn-lg btn-google-plus">
   <i class="fa fa-google-plus"></i>
</a>

它对我来说很顺利。

【讨论】:

    【解决方案4】:

    使用 Font Awesome 图标,我使用以下代码生成了一个带有您选择的颜色的圆形按钮/图像。

    <code>
    
    <span class="fa fa-circle fa-lg" style="color:#ff0000;"></span>
    
    </code>
    

    【讨论】:

      【解决方案5】:

      这是使用 font-awesome 的最佳参考。

      http://bootsnipp.com/snippets/featured/circle-button?

      CSS:

          .btn-circle { width: 30px; height: 30px; text-align: center;padding: 6px 0;font-size: 12px;line-height: 1.428571429;border-radius: 15px;}.btn-circle.btn-lg {width: 50px;height: 50px;padding: 10px 16px;font-size: 18px;line-height:1.33;border-radius: 25px;} 
      

      【讨论】:

        【解决方案6】:

        我遇到了同样的问题,想出了一个非常简单的解决方案working for all (xs, sm, normal and lg) buttons more or less:

        .btn-circle {
            border-radius: 50%;
            padding: 0.1em;
            width:1.8em;
        }
        

        btn-xs 和 -sm 之间的区别只是它们的填充。这个 sn-p 没有涵盖这一点。这个 sn-p 仅根据 font-size 计算大小。

        【讨论】:

          【解决方案7】:

          Boostrap 3 正好有一个组件。它是:

          <span class="badge">100</span>
          

          【讨论】:

          • 如果是图标按钮,不显示文字怎么办?有一个 badge:empty 规则隐藏它。还有什么我应该使用的吗?
          • 这不会给你一个真正的圆形背景。如果它包含一个图标,它将水平拉伸,给人更多的“药丸”外观。
          • @sscirrus 是的,您还可以添加一个类似于其他人发布的二级课程,但非本地更改较少。所以 class="badge badge-circle" 可能只是设置边框半径,您不必设置背景颜色等。
          • 这不会按要求创建圆形按钮。它只会使边缘变圆
          【解决方案8】:

          使用字体很棒的堆叠图标(替代引导徽章)。以下是更多示例:http://fontawesome.io/examples/

           .no-border {
                  border: none;
                  background-color: white;
                  outline: none;
                  cursor: pointer;
              }
          .color-no-focus {
                  color: grey;
              }
            .hover:hover {
                  color: blue;
              }
           .white {
                  color: white;
              }
          <button type="button" (click)="doSomething()" 
          class="hover color-no-focus no-border fa-stack fa-lg">
          <i class="color-focus fa fa-circle fa-stack-2x"></i>
          <span class="white fa-stack-1x">1</span>
          </button>
          <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>

          【讨论】:

            【解决方案9】:

            要在任何按钮中添加圆角边框,最好的方法是添加border-radius 属性。我相信这个类更好,因为你可以在任何按钮大小上添加它。如果设置高度和宽度,则需要为每个按钮大小创建一个“roding”类。

            .btn-circle {
              border-radius: 50%;
            }
            <button class='btn-circle'>Click Me!</button>
            <button class='btn-circle'>?</button>

            【讨论】:

              猜你喜欢
              • 2018-07-23
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2019-12-24
              • 1970-01-01
              • 2018-10-04
              • 1970-01-01
              相关资源
              最近更新 更多