【发布时间】:2017-03-26 04:36:34
【问题描述】:
我在按钮内放置一个图标。要将图标与按钮的右侧对齐,我在图标上使用了float: right。但正如您将看到的,这会导致图标在 Firefox 上溢出,所以我需要另一个解决方案。
注意事项
- 我希望按钮中的文本居中对齐,因此无法在文本中添加
float: left - 图标需要浮动到按钮的右侧
这是图标和按钮的Sass:
.icon-icomoon
font-family: 'icomoon' !important
speak: none
font-style: normal
font-weight: normal
font-variant: normal
text-transform: none
line-height: 1
-webkit-font-smoothing: antialiased
-moz-osx-font-smoothing: grayscale
.icon-arrow-right:before
content: "\e910"
.btn
border-radius: 0
padding: 20px 40px
font-weight: 600
font-family: $fontSansSerif
font-size: 1.9em
span.icon-arrow-right
float: right
font-size: 40px
.mobile-and-tablet-only
display: none
@media screen and (max-width: $mediaBreakpointTablet)
display: block
.desktop-only
display: none
@media screen and (min-width: $mediaBreakpointTablet+1)
display: block
这是按钮的HTML:
<a href="#" class="btn btn-success">
<span class="desktop-only">
Let's make something awesome together
<span class="icon-icomoon icon-arrow-right"></span>
</span>
<span class="mobile-and-tablet-only">
Let's work together
<span class="icon-icomoon icon-arrow-right"></span>
</span>
</a>
这是 Chrome 浏览器中的样子:
这就是它在 Firefox 上的样子。如您所见,文本的宽度为 100%,导致图标溢出:
【问题讨论】: