Search code examples
htmlcssalignmentblockcentering

How to center the block horizontally relative to another block


guys! Please, can someone write how to center .fl and .fr horizontally relative to .footer ? I used pixels to do something similar to centering, but I need to edit to center the elements.

Here is HTML:

<!DOCTYPE html>
<head>
    <title>Google</title>
    <meta charset="utf-8">
    <link href="./style.css" rel="stylesheet">
</head>
<body>
<div class="footer">
    <div class="fl">
        <a href="#" class="fle al">Advertising</a>
        <a href="#" class="fle al">Business</a>
        <a href="#" class="fle al">About</a>
    </div>
    <div class="fr">
        <a href="#" class="fre al">Privacy</a>
        <a href="#" class="fre al">Terms</a>
        <a href="#" class="fre al">Settings</a>
        <a href="#" class="fre al">Use Google.com</a>
    </div>
</div>
</body>
</html>

Here is CSS:

.footer {
    color: #666;
    background: #f2f2f2;
    border-top: 1px solid #e4e4e4;
    position: absolute;
    bottom: 0;
    font-size: 13px;
    height: 37px;
    width:100%;
}

.fl {
    white-space: nowrap;
    position:absolute;
    top:12px;
}

.fr {
    white-space: nowrap;
    position:absolute;
    top:12px;
    right:0;
}

.fle {
    margin-left: 30px;
}

.fre {
    margin-right: 30px;
}

.al:hover {
    text-decoration:underline;
    cursor:pointer;
}

a {
    color:inherit;
    text-decoration:inherit;
}

Solution

  • change your fl and fr classes like below:

      .fl {
      position: relative;
      top: 50%;
      -webkit-transform: translateY(-50%);
      -ms-transform: translateY(-50%);
      transform: translateY(-50%);
      float: left;
      }
      .fr {
      position: relative;
      top: 50%;
      -webkit-transform: translateY(-50%);
      -ms-transform: translateY(-50%);
      transform: translateY(-50%);
      float: right;
      }