Reputation: 3543
I want the spinner to be placed here as a part of the submit input button:
But I'm unable to find a proper solution, here is what I tried:
/*button itself*/
.btn {
font-family: "iransansdnlight";
max-width: 200px;
width: 100%;
background-color: #ad69f4;
border: none;
outline: none;
height: 40px;
border-radius: 49px;
color: #fff;
text-transform: uppercase;
font-weight: 600;
margin: 5px 0;
margin-top: 15px;
cursor: pointer;
transition: 0.5s;
opacity: 1;
}
.btn:not(.disabled):hover {
background-color: #9f5ae7;
}
/*Submit Spinner*/
.submit-container {
display: flex;
flex-direction: row;
max-width: 200px;
width: 100%;
}
.spinner {
font-size: 20px;
position: relative;
display: inline-block;
width: 1em;
height: 1em;
}
.spinner.center {
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
}
.spinner-blade {
position: absolute;
left: 0.4629em;
bottom: 0;
width: 0.074em;
height: 0.2777em;
border-radius: 0.5em;
background-color: transparent;
transform-origin: center -0.2222em;
-webkit-animation: spinner-fade 1s infinite linear;
animation: spinner-fade 1s infinite linear;
}
.spinner-blade:nth-child(1) {
-webkit-animation-delay: 0s;
animation-delay: 0s;
transform: rotate(0deg);
}
.spinner-blade:nth-child(2) {
-webkit-animation-delay: 0.083s;
animation-delay: 0.083s;
transform: rotate(30deg);
}
.spinner-blade:nth-child(3) {
-webkit-animation-delay: 0.166s;
animation-delay: 0.166s;
transform: rotate(60deg);
}
.spinner-blade:nth-child(4) {
-webkit-animation-delay: 0.249s;
animation-delay: 0.249s;
transform: rotate(90deg);
}
.spinner-blade:nth-child(5) {
-webkit-animation-delay: 0.332s;
animation-delay: 0.332s;
transform: rotate(120deg);
}
.spinner-blade:nth-child(6) {
-webkit-animation-delay: 0.415s;
animation-delay: 0.415s;
transform: rotate(150deg);
}
.spinner-blade:nth-child(7) {
-webkit-animation-delay: 0.498s;
animation-delay: 0.498s;
transform: rotate(180deg);
}
.spinner-blade:nth-child(8) {
-webkit-animation-delay: 0.581s;
animation-delay: 0.581s;
transform: rotate(210deg);
}
.spinner-blade:nth-child(9) {
-webkit-animation-delay: 0.664s;
animation-delay: 0.664s;
transform: rotate(240deg);
}
.spinner-blade:nth-child(10) {
-webkit-animation-delay: 0.747s;
animation-delay: 0.747s;
transform: rotate(270deg);
}
.spinner-blade:nth-child(11) {
-webkit-animation-delay: 0.83s;
animation-delay: 0.83s;
transform: rotate(300deg);
}
.spinner-blade:nth-child(12) {
-webkit-animation-delay: 0.913s;
animation-delay: 0.913s;
transform: rotate(330deg);
}
@-webkit-keyframes spinner-fade {
0% {
background-color: #69717d;
}
100% {
background-color: transparent;
}
}
@keyframes spinner-fade {
0% {
background-color: #69717d;
}
100% {
background-color: transparent;
}
}
<div class="submit-container">
<div class="spinner center">
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
</div>
<input class="btn submit disabled" id="submit-register" type="submit" value="ثبت نام" />
</div>
Upvotes: 2
Views: 327
Reputation: 20486
You need to use position:absolute
instead of relative.
You can position it 50%
from top. And since the width/height of the spinner is known, you can use a negative top margin to give some offset based on the center of the spinner.
/*button itself*/
.btn {
font-family: "iransansdnlight";
max-width: 200px;
width: 100%;
background-color: #ad69f4;
border: none;
outline: none;
height: 40px;
border-radius: 49px;
color: #fff;
text-transform: uppercase;
font-weight: 600;
margin: 5px 0;
margin-top: 15px;
cursor: pointer;
transition: 0.5s;
opacity: 1;
}
.btn:not(.disabled):hover {
background-color: #9f5ae7;
}
/*Submit Spinner*/
.submit-container {
display: flex;
flex-direction: row;
max-width: 200px;
width: 100%;
position: relative;
}
.spinner {
font-size: 20px;
position: absolute;
display: inline-block;
width: 1em;
height: 1em;
}
.spinner.center {
left: 7.5%;
top: 50%;
margin-top: -5px;
}
.spinner-blade {
position: absolute;
left: 0.4629em;
bottom: 0;
width: 0.074em;
height: 0.2777em;
border-radius: 0.5em;
background-color: transparent;
transform-origin: center -0.2222em;
-webkit-animation: spinner-fade 1s infinite linear;
animation: spinner-fade 1s infinite linear;
}
.spinner-blade:nth-child(1) {
-webkit-animation-delay: 0s;
animation-delay: 0s;
transform: rotate(0deg);
}
.spinner-blade:nth-child(2) {
-webkit-animation-delay: 0.083s;
animation-delay: 0.083s;
transform: rotate(30deg);
}
.spinner-blade:nth-child(3) {
-webkit-animation-delay: 0.166s;
animation-delay: 0.166s;
transform: rotate(60deg);
}
.spinner-blade:nth-child(4) {
-webkit-animation-delay: 0.249s;
animation-delay: 0.249s;
transform: rotate(90deg);
}
.spinner-blade:nth-child(5) {
-webkit-animation-delay: 0.332s;
animation-delay: 0.332s;
transform: rotate(120deg);
}
.spinner-blade:nth-child(6) {
-webkit-animation-delay: 0.415s;
animation-delay: 0.415s;
transform: rotate(150deg);
}
.spinner-blade:nth-child(7) {
-webkit-animation-delay: 0.498s;
animation-delay: 0.498s;
transform: rotate(180deg);
}
.spinner-blade:nth-child(8) {
-webkit-animation-delay: 0.581s;
animation-delay: 0.581s;
transform: rotate(210deg);
}
.spinner-blade:nth-child(9) {
-webkit-animation-delay: 0.664s;
animation-delay: 0.664s;
transform: rotate(240deg);
}
.spinner-blade:nth-child(10) {
-webkit-animation-delay: 0.747s;
animation-delay: 0.747s;
transform: rotate(270deg);
}
.spinner-blade:nth-child(11) {
-webkit-animation-delay: 0.83s;
animation-delay: 0.83s;
transform: rotate(300deg);
}
.spinner-blade:nth-child(12) {
-webkit-animation-delay: 0.913s;
animation-delay: 0.913s;
transform: rotate(330deg);
}
@-webkit-keyframes spinner-fade {
0% {
background-color: #69717d;
}
100% {
background-color: transparent;
}
}
@keyframes spinner-fade {
0% {
background-color: #69717d;
}
100% {
background-color: transparent;
}
}
<div class="submit-container">
<div class="spinner center">
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
</div>
<input class="btn submit disabled" id="submit-register" type="submit" value="ثبت نام" />
</div>
Upvotes: 3
Reputation: 2705
You have used absolute positioning, so you only need to tweak the left
and top
attributes of the .spinner.center
. I also took the liberty to change the color of your blades, so they are in contrast with the background.
/*button itself*/
.btn {
font-family: "iransansdnlight";
max-width: 200px;
width: 100%;
background-color: #ad69f4;
border: none;
outline: none;
height: 40px;
border-radius: 49px;
color: #fff;
text-transform: uppercase;
font-weight: 600;
margin: 5px 0;
margin-top: 15px;
cursor: pointer;
transition: 0.5s;
opacity: 1;
}
.btn:not(.disabled):hover {
background-color: #9f5ae7;
}
/*Submit Spinner*/
.submit-container {
display: flex;
flex-direction: row;
max-width: 200px;
width: 100%;
}
.spinner {
font-size: 20px;
position: relative;
display: inline-block;
width: 1em;
height: 1em;
}
.spinner.center {
left: 28px;
top: 6px;
margin: auto;
}
.spinner-blade {
position: absolute;
left: 0.4629em;
bottom: 0;
width: 0.074em;
height: 0.2777em;
border-radius: 0.5em;
background-color: transparent;
transform-origin: center -0.2222em;
-webkit-animation: spinner-fade 1s infinite linear;
animation: spinner-fade 1s infinite linear;
}
.spinner-blade:nth-child(1) {
-webkit-animation-delay: 0s;
animation-delay: 0s;
transform: rotate(0deg);
}
.spinner-blade:nth-child(2) {
-webkit-animation-delay: 0.083s;
animation-delay: 0.083s;
transform: rotate(30deg);
}
.spinner-blade:nth-child(3) {
-webkit-animation-delay: 0.166s;
animation-delay: 0.166s;
transform: rotate(60deg);
}
.spinner-blade:nth-child(4) {
-webkit-animation-delay: 0.249s;
animation-delay: 0.249s;
transform: rotate(90deg);
}
.spinner-blade:nth-child(5) {
-webkit-animation-delay: 0.332s;
animation-delay: 0.332s;
transform: rotate(120deg);
}
.spinner-blade:nth-child(6) {
-webkit-animation-delay: 0.415s;
animation-delay: 0.415s;
transform: rotate(150deg);
}
.spinner-blade:nth-child(7) {
-webkit-animation-delay: 0.498s;
animation-delay: 0.498s;
transform: rotate(180deg);
}
.spinner-blade:nth-child(8) {
-webkit-animation-delay: 0.581s;
animation-delay: 0.581s;
transform: rotate(210deg);
}
.spinner-blade:nth-child(9) {
-webkit-animation-delay: 0.664s;
animation-delay: 0.664s;
transform: rotate(240deg);
}
.spinner-blade:nth-child(10) {
-webkit-animation-delay: 0.747s;
animation-delay: 0.747s;
transform: rotate(270deg);
}
.spinner-blade:nth-child(11) {
-webkit-animation-delay: 0.83s;
animation-delay: 0.83s;
transform: rotate(300deg);
}
.spinner-blade:nth-child(12) {
-webkit-animation-delay: 0.913s;
animation-delay: 0.913s;
transform: rotate(330deg);
}
@-webkit-keyframes spinner-fade {
0% {
background-color: white;
}
100% {
background-color: transparent;
}
}
@keyframes spinner-fade {
0% {
background-color: white;
}
100% {
background-color: transparent;
}
}
<div class="submit-container">
<div class="spinner center">
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
<div class="spinner-blade"></div>
</div>
<input class="btn submit disabled" id="submit-register" type="submit" value="ثبت نام" />
</div>
Upvotes: 2