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

OzzC

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);
}
Matt Whitehead

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to vertically align text with icon font?

From Dev

Trying to center align button in td

From Dev

align text center not working as expected

From Dev

The "text-align: center" isn't working in a span element

From Dev

text align center not working

From Dev

Center text above font awesome icon?

From Dev

text-align: center; not working

From Dev

How can I align my icon to be in center of my square box?

From Dev

text-align :center not working

From Dev

Align icon vertically to the center of the first line of text

From Dev

text-align:center not working on custom element

From Dev

How to center align ion icon inside button?

From Dev

<img align="center" not working HTML

From Dev

Align an element to the bottom of the parent and center

From Dev

social icon hover and center align the dropdown list in my menu bar

From Dev

React - Center and resize font awsome icon

From Dev

text-align: center not working in my nav

From Dev

align="center" not working in Firefox and IE

From Dev

Trying to put my icon font above my link to have the same effect Im having with my icon images

From Dev

text align center not working

From Dev

Horizontally center align block element

From Dev

How to align my JTextField to center

From Dev

How to vertically align icon font

From Dev

text-align:center not working on custom element

From Dev

center align icon in circle/disc

From Dev

Align text and icon-font icon in span at center of parent div

From Dev

Font Icon not working in blob image

From Dev

Align icon to left and text to center in react native

From Dev

How to align any element in center?