पैडिंग का उपयोग करके वर्टिकल सेंटरिंग
एक सरल तरीका है पैरेंट कंटेनर पर समान टॉप और बॉटम पैडिंग देना, जिससे चाइल्ड कंटेंट वर्टिकली सेंटर हो जाता है। यह तब काम करता है जब चाइल्ड की ऊंचाई निश्चित या छोटी हो।
उदाहरण
<!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>
आधुनिक विकल्प: फ्लेक्सबॉक्स (display: flex; align-items: center; justify-content: center;) या ग्रिड (display: grid; place-items: center;) अधिक मजबूत और लचीले समाधान हैं।