【问题标题】:How to setup a rounded button in SASS with Ionic Framework icons?如何在 SASS 中使用 Ionic Framework 图标设置圆形按钮?
【发布时间】:2020-05-29 06:02:05
【问题描述】:

我想设置一个圆形按钮,中间有一个离子图标。

我有类似的东西:

button {
    color: white;

    &.button-rounded {
        display: block;
        width: 30px;
        height: 30px;
        line-height: 30px;
        border: 2px solid white;
        border-radius: 50%;
        color: white;
        text-align: center;
        text-decoration: none;
        font-size: 10px;
        font-weight: bold;
    }
}

还有html:

<button class="button button-clear icon ion-home button-rounded"></button>

但结果是这样的:

有什么帮助吗?

【问题讨论】:

  • 你能用它创建一个 Codepen.io 演示吗?
  • 真实的是我之前从未使用过 Codepen.io...:-(
  • 没问题,您只需通过演示复制您的问题。你可以在这里使用 sn-p 或 JSfiddle 或任何对你来说更容易的东西。
  • 不使用 sass:codepen.io/anon/pen/NGpGPg

标签: css sass ionic-framework


【解决方案1】:

问题在于图标的字体大小大于圆形按钮。您可以将 font-size 减小到 24px 并将 line-height 减小到相同的值,以使图标完全适合圆圈内。增加了覆盖选择器的特异性以避免!important

.bar .buttons .button.button-icon .icon::before, .bar .buttons .button.button-icon::before, .bar .buttons .button.button-icon.icon-left::before, .bar .buttons .button.button-icon.icon-right::before {
  font-size: 24px;
  line-height: 24px;
}

Updated Codepen

SASS 版本:

.bar .buttons .button.button-icon {
  .icon::before, &::before, &.icon-left::before, &.icon-right::before {
    font-size: 24px;
    line-height: 24px;
  }
}

【讨论】:

  • 你能举一个使用 SASS 的例子吗?在 SASS 中不适合我。对我来说理想的解决方案是创建一个我相信的新课程。我不希望标题的所有正确按钮都被舍入。
  • 是的,分配一个新类以不影响其他按钮。
  • 我试图创建一个新类但没有成功,这就是为什么我在stackoverflow中询问的原因。您的解决方案不适用于我的情况。 :-'(
  • 它可以在我的 Codepen 链接中使用。与我的代码一起创建您的最新版本以检查有什么不工作。
  • 您的解决方案是让标题中的所有按钮更小 :-( 看看您的 codepen...
猜你喜欢
  • 2013-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-18
  • 2018-09-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多