Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
811 views
in Technique[技术] by (71.8m points)

css animations - CSS Loaders, render multiple on a page

This is probably a silly question; I'm new to CSS, and any help would be much appreciated.

I found a nice CSS loader here https://codepen.io/tstoik/pen/Ywgxqb

It works quite nicely, except it seems that I can only render a single loader per page (or rather, that if I have multiple loaders, they render on top of each other). How can I restructure the CSS so I can have multiple loaders on a page?

For example:

<div class="loader"></div>
<div>
    ...some content
</div>
<div class="loader"></div>

The above example renders the two loaders on top of each other (I believe), making it seem that there is really only a single one.

.loader:before, .loader:after {
  position: absolute;
  top: 50%;
  left: 50%;
  border-radius: 50%;
  border-style: solid;
  border-top-color: #ECD078;
  border-right-color: #C02942;
  border-bottom-color: #542437;
  border-left-color: #53777A;
  content: '';
  transform: translate(-50%, -50%);
  animation: rotate 1.5s  infinite ease-in-out;
}
.loader:before {
  border-width: 5vh;
}
.loader:after {
  width: 15vh;
  height: 15vh;
  border-width: 1vh;
  animation-direction: reverse;
}

@keyframes rotate {
  0% {
    transform: translate(-50%, -50%) rotate(0);
  }
  100% {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Answer from @chriskirknielsen

Adding .loader { position: relative; } works perfectly.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.7k users

...