Search code examples
javascripthtmlcsscenterfont-awesome

Font-Awesome Icons are not centering on page


I have a div that is a page on my site, and I am trying to center these font-awesome icons on it. But for some reason they wont center. I have searched for a solution but none have worked so far.

Click the "about" button to see what I am talking about.

$(function() {
  
  $('#fadeContent').click(function(){
    var bodyContent = $('#bodyContent')
    bodyContent.fadeIn(400);
    bodyContent.click(function() {
      $(this).fadeOut(400);
    })
  });
  
});
body {
  background-color: black;
  font-family: "Source Sans Pro", sans-serif;
  color: #ccc;
  z-index: -100;
  background-color:black;
}

#bodyContent{
  display:none;
  position:absolute;
  color: white;
  width:100%;
  height:100%;
  background:#454545;
  z-index: 100;
}

.fa-times{
    position: absolute;
    top: 0px;
    right: 0px;
    font-size: 3em;
    margin-right: 2%;
    margin-top: 1.5%;
}

.fa-twitter,
.fa-github,
.fa-steam {
    display: inline-block;
    position: relative;
    text-align: center;
    font-size: 2.5em;
    padding: .5em;
    border: 3px solid white;
    margin-top: 20%;
    margin-left: 1.5%;
    margin-right: 1.5%;
}

.fa-times:hover{
    color: #e84d4d;
    cursor: pointer;
}

#home {
    position: absolute;
    width: 16%;
    background-color: transparent;
    border: 2px solid #FFF;
    margin-top: 12%;
    margin-left: 20%;
    height: 3em;
    color: #FFF;
    font-size: 1em;
    cursor: pointer;
    text-transform: uppercase;
    border-radius: 4px;
    animation: fadein 2s;
    -moz-animation: fadein 2s; /* Firefox */
    -webkit-animation: fadein 2s; /* Safari and Chrome */
}

.about {
    position: absolute;
    width: 16%;
    background-color: transparent;
    border: 2px solid #FFF;
    margin-top: 12%;
    margin-left: 37%;
    height: 3em;
    color: #FFF;
    font-size: 1em;
    cursor: pointer;
    text-transform: uppercase;
    border-radius: 4px;
    animation: fadein 2s;
    -moz-animation: fadein 2s; /* Firefox */
    -webkit-animation: fadein 2s; /* Safari and Chrome */
}

#projects {
    position: absolute;
    width: 16%;
    background-color: transparent;
    border: 2px solid #FFF;
    margin-top: 12%;
    margin-left: 54%;
    height: 3em;
    color: #FFF;
    font-size: 1em;
    cursor: pointer;
    text-transform: uppercase;
    border-radius: 4px;
    animation: fadein 2s;
    -moz-animation: fadein 2s; /* Firefox */
    -webkit-animation: fadein 2s; /* Safari and Chrome */
}

#contact {
    position: absolute;
    width: 16%;
    background-color: transparent;
    border: 2px solid #FFF;
    margin-top: 12%;
    margin-left: 71%;
    height: 3em;
    color: #FFF;
    font-size: 1em;
    cursor: pointer;
    text-transform: uppercase;
    border-radius: 4px;
    animation: fadein 2s;
    -moz-animation: fadein 2s; /* Firefox */
    -webkit-animation: fadein 2s; /* Safari and Chrome */
}

#home:hover {
    color: #1dd2e2;
    border: 3px solid #18bdef;
    font-weight: bold;
}

.about:hover {
    color: #1dd2e2;
    border: 3px solid #18bdef;
    font-weight: bold;
}

#projects:hover {
    color: #1dd2e2;
    border: 3px solid #18bdef;
    font-weight: bold;
}

#contact:hover {
    color: #1dd2e2;
    border: 3px solid #18bdef;
    font-weight: bold;
}

@keyframes fadein {
    from {
        opacity:0;
    }
    to {
        opacity:1;
    }
}
@-webkit-keyframes fadein { /* Safari and Chrome */
    from {
        opacity:0;
    }
    to {
        opacity:1;
    }
}
<!DOCTYPE html>

<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    
    <title>Home</title>
    
    <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro|Play" rel="stylesheet">
    
    <link rel='stylesheet prefetch' href='http://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css'>
    <link rel='stylesheet prefetch' href='http://rawgit.com/fralec/elegantShareJS/master/css/elegant.css'>

    <link rel="stylesheet" type="text/css" href="css/style.css">
</head>  
<body>
    
    <button id="home">Home</button>
    <button id="fadeContent" class="about">About</button>
    <button id="projects">Projects</button>
    <button id="contact">Contact</button>
    
      <div id="bodyContent">
          <i class="fa fa-times" aria-hidden="true"></i>
          <i class="fa fa-twitter" aria-hidden="true"></i>
          <i class="fa fa-github" aria-hidden="true"></i>
          <i class="fa fa-steam" aria-hidden="true"></i>
      </div>
    
    <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
    <script src='http://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js'></script>
    <script type="text/javascript" src="js/elegant.js"></script>
    
    <script type="text/javascript" src="js/transition.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript" src="js/background.js"></script>
</body>
</html>


Solution

  • Try this:

    #bodyContent {
        text-align: center;
    }
    

    $(function() {
    
      $('#fadeContent').click(function() {
        var bodyContent = $('#bodyContent')
        bodyContent.fadeIn(400);
        bodyContent.click(function() {
          $(this).fadeOut(400);
        })
      });
    
    });
    body {
      background-color: black;
      font-family: "Source Sans Pro", sans-serif;
      color: #ccc;
      z-index: -100;
      background-color: black;
    }
    
    #bodyContent {
      display: none;
      position: absolute;
      color: white;
      width: 100%;
      height: 100%;
      background: #454545;
      z-index: 100;
      text-align: center;
    }
    
    .fa-times {
      position: absolute;
      top: 0px;
      right: 0px;
      font-size: 3em;
      margin-right: 2%;
      margin-top: 1.5%;
    }
    
    .fa-twitter,
    .fa-github,
    .fa-steam {
      display: inline-block;
      position: relative;
      text-align: center;
      font-size: 2.5em;
      padding: .5em;
      border: 3px solid white;
      margin-top: 20%;
      margin-left: 1.5%;
      margin-right: 1.5%;
    }
    
    .fa-times:hover {
      color: #e84d4d;
      cursor: pointer;
    }
    
    #home {
      position: absolute;
      width: 16%;
      background-color: transparent;
      border: 2px solid #FFF;
      margin-top: 12%;
      margin-left: 20%;
      height: 3em;
      color: #FFF;
      font-size: 1em;
      cursor: pointer;
      text-transform: uppercase;
      border-radius: 4px;
      animation: fadein 2s;
      -moz-animation: fadein 2s;
      /* Firefox */
      -webkit-animation: fadein 2s;
      /* Safari and Chrome */
    }
    
    .about {
      position: absolute;
      width: 16%;
      background-color: transparent;
      border: 2px solid #FFF;
      margin-top: 12%;
      margin-left: 37%;
      height: 3em;
      color: #FFF;
      font-size: 1em;
      cursor: pointer;
      text-transform: uppercase;
      border-radius: 4px;
      animation: fadein 2s;
      -moz-animation: fadein 2s;
      /* Firefox */
      -webkit-animation: fadein 2s;
      /* Safari and Chrome */
    }
    
    #projects {
      position: absolute;
      width: 16%;
      background-color: transparent;
      border: 2px solid #FFF;
      margin-top: 12%;
      margin-left: 54%;
      height: 3em;
      color: #FFF;
      font-size: 1em;
      cursor: pointer;
      text-transform: uppercase;
      border-radius: 4px;
      animation: fadein 2s;
      -moz-animation: fadein 2s;
      /* Firefox */
      -webkit-animation: fadein 2s;
      /* Safari and Chrome */
    }
    
    #contact {
      position: absolute;
      width: 16%;
      background-color: transparent;
      border: 2px solid #FFF;
      margin-top: 12%;
      margin-left: 71%;
      height: 3em;
      color: #FFF;
      font-size: 1em;
      cursor: pointer;
      text-transform: uppercase;
      border-radius: 4px;
      animation: fadein 2s;
      -moz-animation: fadein 2s;
      /* Firefox */
      -webkit-animation: fadein 2s;
      /* Safari and Chrome */
    }
    
    #home:hover {
      color: #1dd2e2;
      border: 3px solid #18bdef;
      font-weight: bold;
    }
    
    .about:hover {
      color: #1dd2e2;
      border: 3px solid #18bdef;
      font-weight: bold;
    }
    
    #projects:hover {
      color: #1dd2e2;
      border: 3px solid #18bdef;
      font-weight: bold;
    }
    
    #contact:hover {
      color: #1dd2e2;
      border: 3px solid #18bdef;
      font-weight: bold;
    }
    
    @keyframes fadein {
      from {
        opacity: 0;
      }
      to {
        opacity: 1;
      }
    }
    
    @-webkit-keyframes fadein {
      /* Safari and Chrome */
      from {
        opacity: 0;
      }
      to {
        opacity: 1;
      }
    }
    <!DOCTYPE html>
    
    <html>
    
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
    
      <title>Home</title>
    
      <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro|Play" rel="stylesheet">
    
      <link rel='stylesheet prefetch' href='http://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css'>
      <link rel='stylesheet prefetch' href='http://rawgit.com/fralec/elegantShareJS/master/css/elegant.css'>
    
      <link rel="stylesheet" type="text/css" href="css/style.css">
    </head>
    
    <body>
    
      <button id="home">Home</button>
      <button id="fadeContent" class="about">About</button>
      <button id="projects">Projects</button>
      <button id="contact">Contact</button>
    
      <div id="bodyContent">
        <i class="fa fa-times" aria-hidden="true"></i>
        <i class="fa fa-twitter" aria-hidden="true"></i>
        <i class="fa fa-github" aria-hidden="true"></i>
        <i class="fa fa-steam" aria-hidden="true"></i>
      </div>
    
      <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
      <script src='http://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js'></script>
      <script type="text/javascript" src="js/elegant.js"></script>
    
      <script type="text/javascript" src="js/transition.js"></script>
      <script type="text/javascript" src="js/index.js"></script>
      <script type="text/javascript" src="js/background.js"></script>
    </body>
    
    </html>