Ahmad Reza
Ahmad Reza

Reputation: 913

css animation unwanted effect

I have a big circle and 3 smaller circles inside the big one. now I want that whenever I hover on big circle these smaller circles move and change their width/height but whenever I try to do it there is an unwanted effect which causes lot of problems. Can someone guide me how to fix it?

.wrapper {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
}

.wrapper .button {
    width : 150px;
    height: 150px;
    border-radius: 50% ;
    background-color: #FFC5B4 ;      
    text-align: center ;
    line-height: 150px; 
}

.button .circle {
    display: inline-block ;
    width: 20px ;
    height: 20px;
    border-radius: 50% ;
    background-color: crimson ;
    transition: all 3s ease-in-out ;
}

.button:hover .circle.num1 { 
    transform: translate(-10em,-10em) ;
    width: 100px ;
    height: 100px;
}

.button:hover .circle.num2 { 
    transform: translateY(-15em) ;
    width: 100px ;
    height: 100px;
}

.button:hover .circle.num3 { 
    transform: translate(10em,-10em) ;
    width: 100px ;
    height: 100px;
}
<body>
    <div class="wrapper">
        <div class="button">
            <span class="circle num1"></span>
            <span class="circle num2"></span>
            <span class="circle num3"></span>
        </div>
    </div>
</body>

Upvotes: 1

Views: 218

Answers (1)

Nimitt Shah
Nimitt Shah

Reputation: 4587

You will need to use position:absolute for circles and margin to place it on the correct position.

Position absolute will remove the boundary for circles.

See below snippet -

.wrapper {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
}

.wrapper .button {
    width : 150px;
    height: 150px;
    border-radius: 50% ;
    background-color: #FFC5B4 ;      
    text-align: center ;
    line-height: 150px; 
}

.button .circle {
    display: inline-block ;
    width: 20px ;
    height: 20px;
    border-radius: 50% ;
    background-color: crimson ;
    transition: all 3s ease-in-out;
    position:absolute;
    margin:auto;
    left:0;
    right:0;
    top:0;
    bottom:0;
}
span.circle.num1{
  margin-left:40px;
}
span.circle.num3{
  margin-right:40px;
}
.button:hover .circle.num1 { 
    transform: translate(-10em,-10em) ;
    width: 100px ;
    height: 100px;
}

.button:hover .circle.num2 { 
    transform: translateY(-15em) ;
    width: 100px ;
    height: 100px;
}

.button:hover .circle.num3 { 
    transform: translate(10em,-10em) ;
    width: 100px ;
    height: 100px;
}
<body>
    <div class="wrapper">
        <div class="button">
            <span class="circle num1"></span>
            <span class="circle num2"></span>
            <span class="circle num3"></span>
        </div>
    </div>
</body>

Upvotes: 2

Related Questions