0

I'm trying to figure out how I can check with CSS if inside a button, an icon comes before or after the text, so I can manipulate it.

For example:

<a href="#" class="button"><i class="fa fa-plus"></i>TEXT</a>

or

<a href="#" class="button">TEXT<i class="fa fa-plus"></i></a>

How can I manipulate the size of the icons, depending on the position relative to the text?

1 Answers1

3

wrap the text with a span and you can do that

a {
  display: block
}

a>span:first-child {
  background: red
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<a href="#" class="button"><span>TEXT</span><i class="fa fa-plus"></i></a>

<hr />

<a href="#" class="button"><i class="fa fa-plus"></i><span>TEXT</span></a>
dippas
  • 58,591
  • 15
  • 114
  • 126
  • 1
    But does this let him style the *icon* differently based upon its position or just the span/text itself? – domsson Jun 28 '17 at 10:59
  • 2
    @domdom, just use `i:first-child` and `i:last-child` to style them differently – Pete Jun 28 '17 at 11:00