Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spacing between Font Awesome icons

Tags:

font-awesome

How can I set spacing between icons that appear in line? Here's my code:

<p>
  <i class="fa fa-facebook fa-2x"></i>
  <i class="fa fa-twitter fa-2x"></i>
  <i class="fa fa-google-plus fa-2x"></i>
</p>

The icons are too close to each other for now.

like image 434
oneday Avatar asked Mar 11 '14 00:03

oneday


People also ask

How do you put a space between Font Awesome icon and text?

I would use the . fa-fw class. For example: <i class="fa fa-cog fa-fw"> This adds a visual space (that won't get stripped out) and it's consistent, so when/if the elements stack it looks a lot better.

How do I put space between icons in CSS?

Just apply a padding (or a margin, depending on the style you've used) between elements, e.g. Show activity on this post. you have to use padding attribute in style tag.


4 Answers

use the fa-fw class:

http://fortawesome.github.io/Font-Awesome/examples/

It's clean, and better than adding a style to your elements.

like image 139
Sparrow 55 Avatar answered Oct 29 '22 07:10

Sparrow 55


Just set a margin as you would do for anything else. Pure CSS.

like image 34
Ciro Costa Avatar answered Oct 29 '22 05:10

Ciro Costa


Actually you can use &nbsp; to create a space

<i class="fa fa-home fa-fw"></i>&nbsp;<i class="fa fa-home fa-fw"></i>
like image 31
TafMakura Avatar answered Oct 29 '22 06:10

TafMakura


Other answers mention the fa-fw class, which works well for a lot of scenarios. However, there are some cases where this is not enough spacing.

For those who use Bootstrap, use me- (margin-right) or ms- (margin-left) classes to specify which side and how much margin.

<!doctype html>
<html lang="en">

<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <!-- Bootstrap CSS -->
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
    integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">

  <!-- Fontsawesome CSS -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"
    integrity="sha512-iBBXm8fW90+nuLcSKlbmrPcLa0OT92xO1BIsZ+ywDWZCvqsWgccV3gFoRBv0z+8dLJgyAHIhR35VZc2oM/gI1w=="
    crossorigin="anonymous" />
  <title>Bootstrap 5.0 Fontsawesome Margin Example</title>
</head>

<body>
  <h1>No Margin</h1>
  <p>
    <i class="fab fa-facebook"></i>
    <i class="fab fa-twitter"></i>
    <i class="fab fa-google-plus"></i>
  </p>

  <h1>ME-1</h1>
  <p>
    <i class="fab fa-facebook me-1"></i>
    <i class="fab fa-twitter me-1"></i>
    <i class="fab fa-google-plus me-1"></i>
  </p>

  <h1>ME-2</h1>
  <p>
    <i class="fab fa-facebook me-2"></i>
    <i class="fab fa-twitter me-2"></i>
    <i class="fab fa-google-plus me-2"></i>
  </p>

  <h1>ME-3</h1>
  <p>
    <i class="fab fa-facebook me-3"></i>
    <i class="fab fa-twitter me-3"></i>
    <i class="fab fa-google-plus me-3"></i>
  </p>

  <h1>ME-4</h1>
  <p>
    <i class="fab fa-facebook me-4"></i>
    <i class="fab fa-twitter me-4"></i>
    <i class="fab fa-google-plus me-4"></i>
  </p>

  <h1>ME-5</h1>
  <p>
    <i class="fab fa-facebook me-5"></i>
    <i class="fab fa-twitter me-5"></i>
    <i class="fab fa-google-plus me-5"></i>
  </p>

  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
    integrity="sha384-j0CNLUeiqtyaRmlzUHCPZ+Gy5fQu0dQ6eZ/xAww941Ai1SxSY+0EQqNXNE6DZiVc"
    crossorigin="anonymous"></script>
</body>

</html>

https://getbootstrap.com/docs/5.0/utilities/spacing/#margin-and-padding

like image 44
BassGod Avatar answered Oct 29 '22 06:10

BassGod