หากต้องการจัดองค์ประกอบในแนวตั้งในแนวตั้งใน CSS ให้ใช้การเติมด้านบนและด้านล่าง
ตัวอย่าง
คุณสามารถลองเรียกใช้รหัสต่อไปนี้เพื่อจัดองค์ประกอบให้อยู่ตรงกลาง
<!DOCTYPE html>
<html>
<head>
<style>
.center {
padding: 50px 0;
border: 2px solid blue;
}
</style>
</head>
<body>
<h2>Center Vertically</h2>
<p>In this example, we use the padding property to center the div element vertically:</p>
<div class = "center">
<p>I am vertically centered.</p>
</div>
</body>
</html> ผลลัพธ์
