Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple CSS spinner works as a DIV but not as a SPAN (or inline DIV)

Tags:

html

css

I need a spinner that I can basically insert into the middle of paragraph text. I have the spinner the way I want it as a block-display element (div), but when I try to create it as a span (or change the div to be inline), the spinner doesn't work.

How can I modify this spinner so that it can be dropped into the middle of a sentence (i.e., paragraph text)?

#loader {
  float: left;
  width: 10px;
  height: 10px;
  margin-right: 5px;
  margin-top: 2px;
  border: 2px solid #f3f3f3;
  border-radius: 50%;
  border-top: 2px solid #3498db;
  -webkit-animation: spin 2s linear infinite;
  animation: spin 2s linear infinite;
}

#loaderInline {
  display: inline;
  width: 10px;
  height: 10px;
  margin-right: 5px;
  margin-top: 2px;
  border: 2px solid #f3f3f3;
  border-radius: 50%;
  border-top: 2px solid #3498db;
  -webkit-animation: spin 2s linear infinite;
  animation: spin 2s linear infinite;
}

@-webkit-keyframes spin {
  0% {
    -webkit-transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(360deg);
  }
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}


/* Add animation to "page content" */

.animate-bottom {
  position: relative;
  -webkit-animation-name: animatebottom;
  -webkit-animation-duration: 1s;
  animation-name: animatebottom;
  animation-duration: 1s
}

@-webkit-keyframes animatebottom {
  from {
    bottom: -100px;
    opacity: 0
  }
  to {
    bottom: 0px;
    opacity: 1
  }
}

@keyframes animatebottom {
  from {
    bottom: -100px;
    opacity: 0
  }
  to {
    bottom: 0;
    opacity: 1
  }
}
<p>
  <div id="loader"></div>Works as normal DIV
</p>

<p>
  <div id="loaderInline"></div>Broken as DIV with inline display
</p>
like image 891
synaptik Avatar asked Dec 05 '25 15:12

synaptik


1 Answers

inline element cannot be sized , inline-block, inline-flex or inline-table does and interact as an inline box.

#loader {
  float: left;
  width: 10px;
  height: 10px;
  margin-right: 5px;
  margin-top: 2px;
  border: 2px solid #f3f3f3;
  border-radius: 50%;
  border-top: 2px solid #3498db;
  -webkit-animation: spin 2s linear infinite;
  animation: spin 2s linear infinite;
}

#loaderInline {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 5px;
  margin-top: 2px;
  border: 2px solid #f3f3f3;
  border-radius: 50%;
  border-top: 2px solid #3498db;
  -webkit-animation: spin 2s linear infinite;
  animation: spin 2s linear infinite;
}

@-webkit-keyframes spin {
  0% {
    -webkit-transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(360deg);
  }
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}


/* Add animation to "page content" */

.animate-bottom {
  position: relative;
  -webkit-animation-name: animatebottom;
  -webkit-animation-duration: 1s;
  animation-name: animatebottom;
  animation-duration: 1s
}

@-webkit-keyframes animatebottom {
  from {
    bottom: -100px;
    opacity: 0
  }
  to {
    bottom: 0px;
    opacity: 1
  }
}

@keyframes animatebottom {
  from {
    bottom: -100px;
    opacity: 0
  }
  to {
    bottom: 0;
    opacity: 1
  }
}
<p>
  <div id="loader"></div>Works as normal DIV
</p>

<p>
  <div id="loaderInline"></div>Broken as DIV with inline display
</p>

You may as well use a pseudo :before/::before and inline-block:

#loader {
  float: left;
  width: 10px;
  height: 10px;
  margin-right: 5px;
  margin-top: 2px;
  border: 2px solid #f3f3f3;
  border-radius: 50%;
  border-top: 2px solid #3498db;
  -webkit-animation: spin 2s linear infinite;
  animation: spin 2s linear infinite;
}

p:before {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 5px;
  margin-top: 2px;
  border: 2px solid #f3f3f3;
  border-radius: 50%;
  border-top: 2px solid #3498db;
  -webkit-animation: spin 2s linear infinite;
  animation: spin 2s linear infinite;
}

@-webkit-keyframes spin {
  0% {
    -webkit-transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(360deg);
  }
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}


/* Add animation to "page content" */

.animate-bottom {
  position: relative;
  -webkit-animation-name: animatebottom;
  -webkit-animation-duration: 1s;
  animation-name: animatebottom;
  animation-duration: 1s
}

@-webkit-keyframes animatebottom {
  from {
    bottom: -100px;
    opacity: 0
  }
  to {
    bottom: 0px;
    opacity: 1
  }
}

@keyframes animatebottom {
  from {
    bottom: -100px;
    opacity: 0
  }
  to {
    bottom: 0;
    opacity: 1
  }
}
<p>
  an inline-block pseudo works too;
</p>
like image 162
G-Cyrillus Avatar answered Dec 07 '25 07:12

G-Cyrillus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!