ChosenJuan
ChosenJuan

Reputation: 961

Unexpected distortion of Font Awesome Icons placed inside CSS created Hexagon

I'm attempting to add social media icons using the Font-awesome i tag with fa class to a Hexagon background. The social media icons should all sit next to each other inside hexagon backgrounds and change background color on hover. However the problems I'm getting are as following:

UPDATE The fiddle is almost right, we just need to be able to make the shpae look like a Hexagon https://jsfiddle.net/onkkdef6/4/

enter image description here

Problems:

1. The social media icons are warped by the hexagon

2. The hexagon now won't change background color on hover

3. The social media icons should be more img-responsive

https://jsfiddle.net/onkkdef6/

HTML

  <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">


            <div class="row">


              <div class="social">
                    <ul>
                    <li><a class="hexagon" href="#"><i class="fa fa-lg fa-linkedin"></i> </a> </li>
                    <li><a class="hexagon" href="#"><i class="fa fa-lg fa-twitter"></i> </a> </li>
                      <li><a class="hexagon" href="#"><i class="fa fa-lg fa-facebook"></i> </a> </li>
                    <li><a class="hexagon" href="#"><i class="fa fa-lg fa-yelp"></i></a></li>
                     <li><a class="hexagon" href="#"><i class="fa fa-lg fa-instagram"></i></a></li>
                    </ul>
                </div>


                      <div class="social">
                    <ul>
                    <li><a class="" href="#"><i class="fa fa-lg fa-linkedin"></i> </a> </li>
                    <li><a class="" href="#"><i class="fa fa-lg fa-twitter"></i> </a> </li>
                      <li><a class="" href="#"><i class="fa fa-lg fa-facebook"></i> </a> </li>
                    <li><a class="" href="#"><i class="fa fa-lg fa-yelp"></i></a></li>
                     <li><a class="" href="#"><i class="fa fa-lg fa-instagram"></i></a></li>
                    </ul>
                </div>


                </div>

CSS:

* { box-sizing: border-box; margin: 0; padding: 0; }



    .hexagon {
        position: relative;
        display: inline-block;
        overflow: hidden;
        margin: 0 8.5%;
        padding: 16%;
        transform: rotate(30deg) skewY(30deg) scaleX(.866); /* .866 = sqrt(3)/2 */
    }
    .hexagon:before{
        display: block;
        position: absolute; /* 86.6% = (sqrt(3)/2)*100% = .866*100% */
        top: 6.7%; right: 0; bottom: 6.7%; left: 0; /* 6.7% = (100% -86.6%)/2 */
        transform: scaleX(1.155) skewY(-30deg) rotate(-30deg); /* 1.155 = 2/sqrt(3) */
        background-color: rgba(30,144,255,.56);
        background-size: cover;
        content: '';
    }


        .social {
        margin: 0;
        padding: 0;
    }

    .social ul {
        margin: 0;
        padding: 5px;
    }

    .social ul li {
        margin: 5px;
        list-style: none outside none;
        display: inline-block;
    }


        .social i {
        width:80px;
        height: 80px;
        color: #FFF;
        background-color: #333;
        font-size: 42px;
        text-align:center;
        padding-top: 25px;

        transition: all ease 0.3s;
        -moz-transition: all ease 0.3s;
        -webkit-transition: all ease 0.3s;
        -o-transition: all ease 0.3s;
        -ms-transition: all ease 0.3s;
    }

    .social i:hover {

        text-decoration: none;
        transition: all ease 0.3s;
        -moz-transition: all ease 0.3s;
        -webkit-transition: all ease 0.3s;
        -o-transition: all ease 0.3s;
        -ms-transition: all ease 0.3s;
    }

        .social .fa-facebook:hover { /* round facebook icon*/
        background: #4060A5;
    }

    .social .fa-twitter:hover { /* round twitter icon*/
        background: #00ABE3;
    }

    .social .fa-yelp:hover { /* round google plus icon*/
        background: #e64522;
    }


    .social .fa-linkedin:hover { /* round linkedin icon*/
        background: #0094BC;
    }


    .social .fa-instagram:hover { /* round instagram icon*/
        background: #375989;
    }

Upvotes: 1

Views: 1991

Answers (2)

ChosenJuan
ChosenJuan

Reputation: 961

I changed the hexagon i scaleX to 2.4 to get the desired hexagon shape I was looking for.

.hexagon i {
    transform: rotate(-45deg) skewY(0) scaleX(2.4);
}

This is the full working css:

* { box-sizing: border-box; margin: 0; padding: 0; }



.hexagon {
    position: relative;
    display: inline-block;
    overflow: hidden;
    margin: 0 8.5%;
    padding: 16%;
    transform: rotate(30deg) skewY(30deg) scaleX(.866); /* .866 = sqrt(3)/2 */
}
.hexagon:before{
    display: block;
    position: absolute; /* 86.6% = (sqrt(3)/2)*100% = .866*100% */
    top: 6.7%; right: 0; bottom: 6.7%; left: 0; /* 6.7% = (100% -86.6%)/2 */
    transform: scaleX(1.155) skewY(-30deg) rotate(-30deg); /* 1.155 = 2/sqrt(3) */
    /* background-color: rgba(30,144,255,.56); */
    background-size: cover;
    content: '';
}


    .social {
    margin: 0;
    padding: 0;
}

.social ul {
    margin: 0;
    padding: 5px;
}

.social ul li {
    margin: 5px;
    list-style: none outside none;
    display: inline-block;
}


    .social i {
    width:80px;
    height: 80px;
    color: #FFF;
    background-color: #333;
    font-size: 42px;
    text-align:center;
    padding-top: 25px;

    transition: all ease 0.3s;
    -moz-transition: all ease 0.3s;
    -webkit-transition: all ease 0.3s;
    -o-transition: all ease 0.3s;
    -ms-transition: all ease 0.3s;
}

.social i:hover {

    text-decoration: none;
    transition: all ease 0.3s;
    -moz-transition: all ease 0.3s;
    -webkit-transition: all ease 0.3s;
    -o-transition: all ease 0.3s;
    -ms-transition: all ease 0.3s;
}

    .social .fa-facebook:hover { /* round facebook icon*/
    background: #4060A5;
}

.social .fa-twitter:hover { /* round twitter icon*/
    background: #00ABE3;
}

.social .fa-yelp:hover { /* round google plus icon*/
    background: #e64522;
}


.social .fa-linkedin:hover { /* round linkedin icon*/
    background: #0094BC;
}


.social .fa-instagram:hover { /* round instagram icon*/
    background: #375989;
}

.hexagon i {
    transform: rotate(-45deg) skewY(0) scaleX(2.4);
}

Thanks to Mike Barwick who helped me figure out most of the answer. Thanks to his help I was able to solve my problem.

This is the working fiddle: https://jsfiddle.net/onkkdef6/5/

Upvotes: 2

Mike Barwick
Mike Barwick

Reputation: 5367

You're transforming the child elements - and shouldn't be. Just revert the icons back - like so (but make sure this is after .hexagon:after):

.hexagon i {
    transform: rotate(-45deg) skewY(0) scaleX(1.866);
}

Working example: https://jsfiddle.net/onkkdef6/4/

If you're unable to play around with the scales and CSS to fit your needs, maybe you can use a library like this. Looks to be exactly what you want.

http://ninodezign.com/css3-hexagon-buttons/

Upvotes: 1

Related Questions