如何垂直居中元素

学习如何使用 CSS 将元素垂直和水平居中。

我是垂直和水平居中的。

如何垂直居中任意元素

အကြောင်းအရာ

<style>
.container {
  height: 200px;
  position: relative;
  border: 3px solid green;
}
.vertical-center {
  margin: 0;
  position: absolute;
  top: 50%;
  -ms-transform: translateY(-50%);
  transform: translateY(-50%);
}
</style>
<div class="container">
  

I am vertically centered.

</div> </div>

ကိုယ်တိုင် ဆောက်လုပ်ကြပါ

如何垂直和水平居中

အကြောင်းအရာ

<style>
.container {
  height: 200px;
  position: relative;
  border: 3px solid green;
}
.center {
  margin: 0;
  position: absolute;
  top: 50%;
  left: 50%;
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}
</style>
<div class="container">
  <div class="center">
    <p>I am vertically and horizontally centered.</p>
  </div>
</div>

ကိုယ်တိုင် ဆောက်လုပ်ကြပါ

ကျော်ကြားလျက် Flexbox ကို အကိုင်းအခါ အရှိန်ထိပ်ချက်များ ကို အလိုက်လျက် စီးဆင်းလိုက်ပါ

အကြောင်းအရာ

.center {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 200px;
  border: 3px solid green;
}

ကိုယ်တိုင် ဆောက်လုပ်ကြပါ

ပါဝင်သော စာမျက်နှာ

教程:CSS စီးဆင်း

教程:CSS ပြောင်းလဲခြင်း

教程:CSS Flexbox