0

I'm trying to apply a style to but when I try to apply style directly to the class ".fa {}", it looks different than when I apply it to the "#contact a {}"

/*
.fa {
  padding: 40px;
  font-size: 30px;
  width: 30px;
  text-align: center;
  text-decoration: none;
  margin: 15px;
  border-radius: 50%;
}
*/

#contact>a {
  padding: 40px;
  font-size: 30px;
  width: 30px;
  text-align: center;
  text-decoration: none;
  margin: 15px;
  border-radius: 50%;
}

.fa:hover {
  opacity: 0.7;
}

.fa-facebook {
  background: #3B5998;
  color: white;
}

.fa-twitter {
  background: #55ACEE;
  color: white;
}

.fa-google {
  background: #dd4b39;
  color: white;
}

.fa-linkedin {
  background: #007bb5;
  color: white;
}

.fa-youtube {
  background: #bb0000;
  color: white;
}

.fa-instagram {
  background: #125688;
  color: white;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<section id="contact">
  <a href="#" class="fa fa-facebook"></a>
  <a href="#" class="fa fa-twitter"></a>
  <a href="#" class="fa fa-google"></a>
  <a href="#" class="fa fa-linkedin"></a>
  <a href="#" class="fa fa-youtube"></a>
  <a href="#" class="fa fa-instagram"></a>
</section>
Carl Binalla
  • 5,393
  • 5
  • 27
  • 46

2 Answers2

2

It is because .fa default css apply first when you use .fa class, its affect font-size:30px, so use a.fa or override font-size of default .fa using !important

.fa {
    display: inline-block;
    font: normal normal normal 14px/1 FontAwesome;
    font-size: inherit;
    text-rendering: auto;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/*
.fa {
  padding: 40px;
  font-size: 30px;
  width: 30px;
  text-align: center;
  text-decoration: none;
  margin: 15px;
  border-radius: 50%;
}
*/

a.fa {
  padding: 40px;
  font-size: 30px;
  width: 30px;
  text-align: center;
  text-decoration: none;
  margin: 15px;
  border-radius: 50%;
}

.fa:hover {
  opacity: 0.7;
}

.fa-facebook {
  background: #3B5998;
  color: white;
}

.fa-twitter {
  background: #55ACEE;
  color: white;
}

.fa-google {
  background: #dd4b39;
  color: white;
}

.fa-linkedin {
  background: #007bb5;
  color: white;
}

.fa-youtube {
  background: #bb0000;
  color: white;
}

.fa-instagram {
  background: #125688;
  color: white;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<section id="contact">
  <a href="#" class="fa fa-facebook"></a>
  <a href="#" class="fa fa-twitter"></a>
  <a href="#" class="fa fa-google"></a>
  <a href="#" class="fa fa-linkedin"></a>
  <a href="#" class="fa fa-youtube"></a>
  <a href="#" class="fa fa-instagram"></a>
</section>
Hiren Vaghasiya
  • 5,454
  • 1
  • 11
  • 25
0

you can simply write your CSS below the font-awesome CSS.

For example -

        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <style>
/*
.fa {
  padding: 40px;
  font-size: 30px;
  width: 30px;
  text-align: center;
  text-decoration: none;
  margin: 15px;
  border-radius: 50%;
}
*/

#contact>a {
  padding: 40px;
  font-size: 30px;
  width: 30px;
  text-align: center;
  text-decoration: none;
  margin: 15px;
  border-radius: 50%;
}

.fa:hover {
  opacity: 0.7;
}

.fa-facebook {
  background: #3B5998;
  color: white;
}

.fa-twitter {
  background: #55ACEE;
  color: white;
}

.fa-google {
  background: #dd4b39;
  color: white;
}

.fa-linkedin {
  background: #007bb5;
  color: white;
}

.fa-youtube {
  background: #bb0000;
  color: white;
}

.fa-instagram {
  background: #125688;
  color: white;
}

    </style>
    <section id="contact">
      <a href="#" class="fa fa-facebook"></a>
      <a href="#" class="fa fa-twitter"></a>
      <a href="#" class="fa fa-google"></a>
      <a href="#" class="fa fa-linkedin"></a>
      <a href="#" class="fa fa-youtube"></a>
      <a href="#" class="fa fa-instagram"></a>
    </section>
Deepak
  • 55
  • 6