Centralize loading on the page

Asked

Viewed 1,140 times

3

I’m riding a load and I’m having 2 problems.

How to leave the div circle that contains the animation in the vertical and horizontal center of the screen.

2º How to leave the tips of the load rounded.

.loading {
    background: #000;
    position: fixed;
    left: 0px;
    top: 0px;
    width: 100%;
    height: 100%;
    z-index: 1000;
}
.circle {
  width: 80px;
  height: 80px;
  border-radius: 40px;
  box-sizing: border-box;
  border: solid 10px rgba(255, 255, 255, 0.2);
  border-top-color: #FFF;
  animation: spin 1s infinite linear;
}

@keyframes bouncy {
  40% {
    height: 40px;
  }
  50% {
    transform: translate(0, 65px);
    height: 34px;
    border-radius: 20px;
  }
  65% {
    height: 40px; 
  }
}

@keyframes push {
  50% {
    margin-left: 56px;
  }
}

@keyframes slide {
  50% {
    margin-top: 25px;
  }
}

@keyframes pulse { 
  50% { 
    border-width: 30px;
  } 
}

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

@keyframes cross {
  50% {
    margin-left: 60px;
  }
}
<!-- Loading -->
        <div class="loading">
            <div class="circle"></div>
        </div>

1 answer

5


Hello, to center one element vertically and horizontally within another, one should place these styles:

.circle{
  left:50%;
  top:50%;
  position: relative;
  margin-left:-40px; /* -1/2 width */
  margin-top:-40px; /* -1/2 height */
}

This solution is compatible with all browsers, old and modern. The margin on the left should be -(half the width of the element), and the margin on the top should be -(half the height of the element).

I put your code in this fiddle for example, with the correction

https://jsfiddle.net/tsgsda2x/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.