Is it possible to get the code below to resize the animation to any length of body text?
Hi there,
I'm not a frontend developer and wondered if anybody might be able to help me by pointing me in the direction of how to resize the container div block to accommodate any length of string in the place of "Learn More". Ideally, is it possible to implement this in pure CSS or do I have to get javascript involved?
The problem I have is that I'm trying to get the parent to animate to the width of the child, not the child to animate to the width of the parent.
I've had a go at using inline-flex but either I'm using it wrong or it is not the solution to the problem. Any help would be much appreciated.
Thanks in advance.
@import url("https://fonts.googleapis.com/css?family=Mukta:700");
body {
font-family: "Mukta", sans-serif;
font-size: 1rem;
line-height: 0.9;
display: flex;
align-items: center;
justify-content: center;
margin: 0;
background: #f3f8fa;
}
button {
position: relative;
display: inline-block;
cursor: pointer;
outline: none;
border: 0;
text-decoration: none;
background: transparent;
padding: 0;
font-size: inherit;
font-family: inherit;
}
.learn-more {
width: 12rem;
height: auto;
}
.learn-more .circle {
transition: all 0.45s cubic-bezier(0.65, 0, 0.076, 1);
position: relative;
margin: 0;
width: 3rem;
height: 3rem;
background: #282936;
border-radius: 1.625rem;
}
.learn-more .circle .icon {
transition: all 0.45s cubic-bezier(0.65, 0, 0.076, 1);
position: absolute;
top: 0;
bottom: 0;
margin: auto;
background: #fff;
}
.learn-more .circle .icon.arrow {
transition: all 0.45s cubic-bezier(0.65, 0, 0.076, 1);
left: 0.625rem;
width: 1.125rem;
height: 0.125rem;
background: none;
}
.learn-more .circle .icon.arrow::before {
position: absolute;
content: "";
top: -0.25rem;
right: 0.0625rem;
width: 0.625rem;
height: 0.625rem;
border-top: 0.125rem solid #fff;
border-right: 0.125rem solid #fff;
transform: rotate(45deg);
}
.learn-more .button-text {
transition: all 0.45s cubic-bezier(0.65, 0, 0.076, 1);
position: relative;
top: 0;
left: 0;
right: 0;
bottom: 0;
padding: 0.75rem 0;
margin: 0 0 0 4rem;
color: #282936;
font-weight: 700;
line-height: 1.6;
text-align: left;
text-transform: uppercase;
white-space: nowrap;
}
.learn-more:hover .circle {
width: 100%;
}
.learn-more:hover .circle .icon.arrow {
background: #fff;
transform: translate(1rem, 0);
}
.learn-more:hover .button-text {
color: #fff;
}
<div id="container">
<div class="learn-more">
<div class="circle">
<span class="icon arrow"></span>
<p class="button-text">Learn More</p>
</div>
</div>
</div>