JSFiddle - React, Tailwind, and code Playground

by Tìm ở đây Khoá học CNTT

HTML

<h2>Căn giữa</h2>
<p>Trong ví dụ này, chúng ta sử dụng position và thuộc tính transform để căn giữa theo chiều ngang và chiều dọc </p>

<div class="center">
  <p>Căn giữa theo chiều ngang và chiều dọc.</p>
</div>

CSS

.center { 
  height: 200px;
  position: relative;
  border: 3px solid green; 
}

.center p {
  margin: 0;
  position: absolute;
  top: 50%;
  left: 50%;
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}