html - 简单的 CSS 微调器作为 DIV 而不是 SPAN(或内联 DIV)

标签 html css

我需要一个基本上可以插入段落文本中间的微调器。我按照我希望的方式将微调器作为 block 显示元素 (div),但是当我尝试将其创建为跨度(或将 div 更改为内联)时,微调器不起作用。

我如何修改这个微调器,以便它可以放在句子的中间(即段落文本)?

#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>

最佳答案

inline 元素无法调整大小,inline-blockinline-flexinline-table 可以并且作为内联框进行交互。

#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>


你也可以使用伪 :before/::beforeinline-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>

关于html - 简单的 CSS 微调器作为 DIV 而不是 SPAN(或内联 DIV),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42860929/

相关文章:

javascript - HTML 显示和隐藏在 Mozilla Firefox 中不起作用

html - Font Awesome 显示为正方形

javascript - 将代码动态 append 到选择的元素

html - 内联 block 之间的间距

javascript - 如何仅在 HTML 表单验证成功时执行一组 JavaScript 代码

javascript - jQuery:如何从 parent 那里找到 sibling

html - Primeng 禁用按钮悬停时会改变颜色

javascript - 简单的 Accordion 菜单 (jQuery)

html - 这个要点 <li> 没有显示圆圈是什么意思?

css - Bootstrap单页全屏布局响应高度