Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Float icon inside button to the right

Tags:

html

css

sass

I'm positioning an icon inside a button. To align the icon to the right of the button, I'm using float: right on the icon. But as you'll see, this causes the icon to overflow on Firefox, so I need another solution.

Things to note

  1. I want the text in the button to be centrally aligned, so adding float: left to the text isn't an option
  2. The icon needs to be floated to the right of the button

Here's the Sass for the icon and button:

.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

Here's the HTML for the button:

<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>

Here's what it looks like in the browser on Chrome:

What the button looks like on Chrome

And here's what it looks like on Firefox. As you can see, the width of the text is at 100% which is causing the icon to overflow:

Button on Firefox

like image 319
dspacejs Avatar asked Oct 30 '22 10:10

dspacejs


1 Answers

Try giving the a.btn position:relative and then positioning the span.icon-arrow-right absolutely (position: absolute). Then you can give the arrow icon any desired position by adding right: 3%; top: 33% to it.

like image 189
stevenpslade Avatar answered Nov 15 '22 06:11

stevenpslade