ফ্লেক্সবক্স ব্যবহার করে কোনো বাটন (বা যেকোনো এলিমেন্ট) কন্টেইনারের মধ্যে পুরোপুরি কেন্দ্রে আনন্দা যায়।
উদাহরণ: বাটন কেন্দ্রিকরণ
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
.centered {
display: flex;
justify-content: center;
align-items: center;
height: 200px;
border: 3px solid rgb(0, 70, 128);
}
button{
font-size: 18px;
border: none;
padding:10px;
background-color: darkblue;
color:white;
}
</style>
</head>
<body>
<h1>কেন্দ্রিকরণ উদাহরণ</h1>
<div class="centered">
<button>এই বাটনটি কেন্দ্রে আছে</button>
</div>
</body>
</html>
কোড ব্যাখ্যা
- display: flex: ফ্লেক্স কন্টেইনার তৈরি করে।
- justify-content: center: অনুভূমিক কেন্দ্রিকরণ।
- align-items: center: লম্বা কেন্দ্রিকরণ।
- height: 200px: কন্টেইনারের উচ্চতা নির্ধারণ করলেই কেন্দ্রিকরণ দৃশ্যমান হয়।
অন্য পদ্ধতি
Grid (`place-items: center`), Absolute Positioning (`top:50%; left:50%; transform: translate(-50%,-50%)`) দিয়েও করা যায়। ফ্লেক্সবক্স সবচেয়ে সহজ এবং রেসপন্সিভ।