Spacing between the glyphicon and text?
Asked Answered
S

4

6

I am trying to add a glyph icon as part of an email address link. The icon shows but there is no spacing between the icon and the email address text (I want the hyperlink to include both the icon and the text... including the space). What's the best way to accomplish this?

       <a href="mailto:someone@somewheredotcom" title="Some Email">
        <span class="glyphicon glyphicon-envelope">someone@somewheredotcom</span>
    </a> 
Solve answered 17/5, 2015 at 18:18 Comment(0)
U
8

You can try to do this:

.glyphicon-envelope:before {
  margin-right: 5px;
}

Be aware that your custom css file should be included after bootstrap.css

Uraemia answered 23/5, 2015 at 21:11 Comment(1)
This worked for me. Thanks. I did: .glyphicon:before { margin-right: 5px; }Streetlight
G
8

If you using only glyphicon just add one space after </span> tag like below

<a href="#" class="btn btn-primary"><span class="glyphicon glyphicon-user"></span> Individual</a>

If you using glyphicon along with font awesome library reference just add fa-fw at the end of class.

<a href="mailto:someone@somewheredotcom" title="Some Email">
    <span class="glyphicon glyphicon-envelope fa-fw">someone@somewheredotcom</span>
</a> 
Genisia answered 29/2, 2016 at 1:7 Comment(0)
C
4

From http://getbootstrap.com/components/, see this note

Be sure to leave a space between the icon and text for proper padding.

So, you can modify the CSS if desired, for example using Bogdan's idea, or just by adding &nbsp; between the icon and your text:

<a href="mailto:someone@somewheredotcom" title="Some Email">
    <span class="glyphicon glyphicon-envelope" aria-hidden="true"></span>&nbsp;someone@somewheredotcom
</a>
Crockett answered 29/6, 2016 at 17:12 Comment(0)
B
1

According to Bootstrap:

Icon classes should only be used on elements that contain no text content and >have no child elements.

You should put the email address outside of span:

<span class="glyphicon glyphicon-envelope fa-fw"></span>someone@somewheredotcom
Barnaba answered 5/5, 2016 at 22:8 Comment(1)
What you're saying is true, but it will not add the spacing like the OP was looking for.Crockett

© 2022 - 2024 — McMap. All rights reserved.