"إذا أراد العامل أن يؤدي عمله بشكل جيد، فعليه أولاً أن يشحذ أدواته." - كونفوشيوس، "مختارات كونفوشيوس. لو لينجونج"
الصفحة الأمامية > برمجة > 如何在Chrome中居中选择框文本?

如何在Chrome中居中选择框文本?

نشر في 2025-05-01
تصفح:822

How Can I Center Text in a Select Box (A Chrome-Specific Solution)?

Text Alignment for Select Box: A Partial Chrome-Only Solution

You may wish to center the text within a select box for aesthetic reasons or to improve accessibility. However, manually adding a text-align attribute to the select element in CSS may not work as expected.

Initial Attempts

One common approach is illustrated in the fiddle provided:

<pre>

&lt;option value=""&gt;(please select a state)&lt;/option&gt;
&lt;option>

</select>
</pre>

<pre>select .lt { text-align: center; }
</pre>

Unfortunately, this technique is ineffective.

Chrome-Specific Solution

While a CSS-only solution for complete text alignment may not be possible across all browsers, there is a partial solution for Chrome:

<pre>select { width: 400px; text-align-last:center; }
</pre>

This method centers the selected option in the dropdown itself but not the unselected options. It is a step closer to full alignment but also a limitation to be aware of.

أحدث البرنامج التعليمي أكثر>

تنصل: جميع الموارد المقدمة هي جزئيًا من الإنترنت. إذا كان هناك أي انتهاك لحقوق الطبع والنشر الخاصة بك أو الحقوق والمصالح الأخرى، فيرجى توضيح الأسباب التفصيلية وتقديم دليل على حقوق الطبع والنشر أو الحقوق والمصالح ثم إرسالها إلى البريد الإلكتروني: [email protected]. سوف نتعامل مع الأمر لك في أقرب وقت ممكن.

Copyright© 2022 湘ICP备2022001581号-3