Right align font icon

Asked

Viewed 3,872 times

3

I try to align an ico font on the right side of the screen within a header HEADER, but I can’t even use one float: right. But then it goes to the right, however I lose the other alignment settings. I want to send these three bars to the right side. Image below:

inserir a descrição da imagem aqui

This is my html:

<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Test Font</title>
<!-- Link para Icon Fontes Externos -->
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
</head>
<body>
    <header>
        <i class="fa fa-search"></i>
        <h1 class="logo">Sample Sample</h1>
        <i class="fa fa-bars"></i>
    </header>
</body>
</html>

This is my CSS:

   *{padding: 0; 
      margin: 0;
      }

    body{
        font-family: arial, helvetica, freesans, sans-serif;
        font-style: normal;
    }

    header{
        height: 70px;
        line-height: 70px;
        background: #674323;
        color: white;
        font-size: 1.3em;
    }

    header .logo{
        text-align: center;
        display: inline-block;
        margin: 0 auto;
        text-shadow: 1px 1px 1px black;
    }

    .fa-search{
        font-size: 1.58em;
        text-align: left;
        margin-left: 20px;

    }

    .fa-bars{
        display: inline-block;
        font-size: 1.8em;
        text-align: right;
        margin-right: 20px;
        border-radius: 10px;
        background: white;
        color: #674323;
        padding: 2px 5px 1px 5px;
        box-size: border-box;
        vertical-align: middle;
    }
  • 1

    Luitame, you could use position: absolute;... http://jsfiddle.net/2H3Lc/

2 answers

4

One possibility is to make this icon have closed position, ie with position: absolute;

To do this, just use this CSS:

 .fa-bars {
     position: absolute;
     right: 20px;
     top: 15px;

To have this effect: http://jsfiddle.net/2H3Lc/

2

inserir a descrição da imagem aqui

If that’s the way you want to show off just give one float: right and a margin: 15px 40px 0 0 (margin spacing is at your discretion).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.