OzzC
OzzC

Reputation: 821

Trying to align my icon font element at center is not working

I´m trying to do an effect when I hover over an image, I want to show a dark box closing and when the box is closed, I Want to show an icon font on the center of my image.

The effect already is working but my icon font is not staying centered.

I already tried margin:0 auto, text-align:center, but nothing is working.

I format my icon font here:

#info>i 
    {
        font-size:1.7em;
        color:#ccc;
        margin:0 auto;
    } 

But only the color and font-size are working, the margin, text-align etc. don't work. Does anybody understand what can be happening here?

My jsfiddle showing the problem:

http://jsfiddle.net/mibb/TLSSN/

My Html:

<div class="view second-effect">
      <img src="image1.jpg"  />
      <div class="mask">
      <a href="#" id="info"><i class="fa fa-download"></i></a>       
</div>

My CSS:

#info>i 
{
    font-size:1.7em;
    color:#ccc;
    margin:0 auto;
} 

.view a#info 
{
    display: inline-block;
    padding:0;
    width:20px;
    height:20px;
}

.view 
{
    width: 155px;
    height: 160px;
    float: left;
    overflow: hidden;
    position: relative;
    text-align: center;
    box-shadow: 0px 0px 5px #aaa;
    cursor: default;
    margin-right:20px; 
    border:3px solid #ccc;
    margin-top:4px; 
}

.view .mask, .view .content 
{
    width: 155px;
    height: 160px;
    position: absolute;
    overflow: hidden;
    top: 0;
    left: 0;
}

.second-effect .mask 
{
    opacity: 0;
    overflow:visible;
    border:0px solid rgba(0,0,0,0.7);
    -moz-box-sizing:border-box;
    -webkit-box-sizing:border-box;
    box-sizing:border-box;
    -webkit-transition: all 0.4s ease-in-out;
    -moz-transition: all 0.4s ease-in-out;
    -o-transition: all 0.4s ease-in-out;
    -ms-transition: all 0.4s ease-in-out;
    transition: all 0.4s ease-in-out;
}

.second-effect:hover .mask 
{
    opacity: 1;
    border:78px solid rgba(0,0,0,0.7);
}

Upvotes: 0

Views: 589

Answers (1)

Matt Whitehead
Matt Whitehead

Reputation: 1811

So I'm pretty sure you're aligning your icon's 0,0 coordinate to the center instead of aligning the center of the icon to the center of the parent.

I made your fiddle work by adding this:

margin-top:-12px;
margin-bottom:-12px;

// This would work too
margin: -12px 0;

JSFiddle

Btw, you can add font awesome, or any other external file, to a JSFiddle through the External Resources tab on the left side.

Upvotes: 1

Related Questions