Align block to the center (position)

https://habr.com/ru/post/238449

by Serhio Magpie

HTML

<div class="parent">
  <div class="block">
    <img src="https://habrastorage.org/files/50f/7b2/1cc/50f7b21ccabd4b20bc0369f228138b5b.jpg" alt="">
  </div>
</div>

CSS

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.parent {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  overflow: auto;
}

.block {
  width: 250px;
  height: 250px;
  position: absolute;
  top: 50%;
  left: 50%;
  margin: -125px 0 0 -125px;
  background: #60a839;
}

.block img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
  border: none;
}