0

I try using transform:scale(1.2) to obtain the effect of an appearing circle around the icon. transform I added to the .icon-style:hover::after.

Now this code is commented, please uncomment this code to see what I want to get.

For example I trying doing something like this: click. But scale change position circle.

I read this article, but I don't now how to use transform-origin in my CSS.

Demo: JSFiddle

*{
    background-color: black;
}
.pos-footer {
    position: absolute;
    bottom: 20px;
    right: 30px;
}
.icon-social {
    display: flex;
}
.icon-social-pos {
    position: relative;
}
.icon-style {
    position: relative;
    background-repeat: no-repeat;
    background-position: center; 
    width: 30px;
    height: 30px;
    background-color: rgba(255, 255, 255, 0.25);
    padding: 10px;
    border-radius: 50%;
    transition: background-color .3s ease-in-out;
}
.icon-style:hover {
    background-color: rgba(255, 255, 255, 0.7);
}
.icon-style::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1;
    width: 100%;
    height: 100%;
    border: 5px solid rgba(255, 255, 255, 0.425);
    border-radius: 50%;
    padding: 7px;
    opacity: 0;
    transition: all .4s ease-in-out;
}
.icon-style:hover::after {
    opacity: 1;
    /* transform: scale(1.2); */
}
.icon-github {
    background-image: url("https://img.icons8.com/windows/30/000000/github.png");
    margin-right: 10px;
}
.icon-linkedin {
    background-image: url("https://img.icons8.com/ios-glyphs/22/000000/linkedin-2.png");
    margin-left: 10px;
}
<div class="pos-footer">
    <div class="icon-social">
        <a href="#">
            <div class="icon-social-pos">
                <div class="icon-style icon-github"></div>
            </div>
        </a>
        <a href="#">
            <div class="icon-social-pos">
                <div class="icon-style icon-linkedin"></div>
            </div>
        </a>
    </div>
</div>
Temani Afif
  • 245,468
  • 26
  • 309
  • 415
michal
  • 1,534
  • 5
  • 28
  • 62
  • 1
    unlike the accepted answer, you can add the scale at the end to avoid changing the origin (like in the duplicate) – Temani Afif Feb 20 '19 at 20:01

1 Answers1

2

First of all, the transform in your hover (.icon-style:hover::after) is overwriting your transform: translate(-50%, -50%);. A way to fix it is to add the translate to the hover too:

.icon-style:hover::after {
    opacity: 1;
    transform: scale(1.2) translate(-50%, -50%);
}

Then you have to define your transform-origin in .icon-style to top left;

*{
    background-color: black;
}
.pos-footer {
    position: absolute;
    bottom: 20px;
    right: 30px;
}
.icon-social {
    display: flex;
}
.icon-social-pos {
    position: relative;
}
.icon-style {
    position: relative;
    background-repeat: no-repeat;
    background-position: center; 
    width: 30px;
    height: 30px;
    background-color: rgba(255, 255, 255, 0.25);
    padding: 10px;
    border-radius: 50%;
    transition: background-color .3s ease-in-out;
}
.icon-style:hover {
    background-color: rgba(255, 255, 255, 0.7);
}
.icon-style::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transform-origin: top left;
    z-index: 1;
    width: 100%;
    height: 100%;
    border: 5px solid rgba(255, 255, 255, 0.425);
    border-radius: 50%;
    padding: 7px;
    opacity: 0;
    transition: all .4s ease-in-out;
}
.icon-style:hover::after {
    opacity: 1;
    transform: scale(1.2) translate(-50%, -50%);
}
.icon-github {
    background-image: url("https://img.icons8.com/windows/30/000000/github.png");
    margin-right: 10px;
}
.icon-linkedin {
    background-image: url("https://img.icons8.com/ios-glyphs/22/000000/linkedin-2.png");
    margin-left: 10px;
}
<div class="pos-footer">
    <div class="icon-social">
        <a href="#">
            <div class="icon-social-pos">
                <div class="icon-style icon-github"></div>
            </div>
        </a>
        <a href="#">
            <div class="icon-social-pos">
                <div class="icon-style icon-linkedin"></div>
            </div>
        </a>
    </div>
</div>
agustin
  • 2,187
  • 2
  • 22
  • 40