যদি সন্তানের উপাদানটি ইনলাইন হয় (যেমন একটি নয় div, tableইত্যাদি) তবে আমি এটিকে একটি divবা এ pএর মধ্যে গুটিয়ে রাখি এবং মোড়কের পাঠ্য সিএসএস সম্পত্তিটিকে কেন্দ্রের সমান করে রাখি।
<div id="container">
This text is aligned to the left.<br>
So is this text.<br>
<div style="text-align: center">
This <button>button</button> is centered.
</div>
This text is still aligned left.
</div>
অন্যথায়, যদি উপাদানটি একটি নির্দিষ্ট প্রস্থের একটি ব্লক ( display: blockযেমন, একটি divবা ক p) হয় তবে আমি এর মার্জিন বাম এবং ডান সিএসএস বৈশিষ্ট্যগুলিকে অটোতে সেট করব।
<div id="container">
This text is aligned to the left.<br>
So is this text.<br>
<div style="margin: 0 auto; width: 200px; background: red; color: white;">
My parent is centered.
</div>
This text is still aligned left.
</div>
আপনি অবশ্যই text-align: centerএর বিষয়বস্তুকে কেন্দ্রিক করে তোলার জন্য মোড়কের উপাদানটিতে একটি যুক্ত করতে পারেন।
আমি অবস্থান নিয়ে বিরক্ত করব না কারণ আইএমএইচও এটি ওপিএস সমস্যার সমাধানের উপায় নয় তবে এই লিঙ্কটি পরীক্ষা করে দেখুন, খুব সহায়ক।