လုပ်နည်း - Elements များကို ဒေါင်လိုက် အလယ်ဗဟိုထားပါ။
ဒြပ်စင်တစ်ခုအား 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">
<div class="vertical-center">
<p>I am vertically centered.</p>
</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 Align Tutorial သို့ သွား ပါ။
အကြံပြုချက်- ဒြပ်စင်များကို အတိုင်းအတာမည်ကဲ့သို့ အတိုင်းအတာကို ပိုမိုလေ့လာရန် ကျွန်ုပ်တို့၏ CSS Transform Tutorial သို့ သွား ပါ။
အကြံပြုချက်- flexbox ပိုမိုလေ့လာရန် ကျွန်ုပ်တို့၏ CSS Flexbox ကျူတိုရီရယ် သို့ သွားပါ ။