How to Align Form Input Labels to the Right?

Linda Hamilton
Release: 2024-11-06 21:29:02
Original
574 people have browsed it

How to Align Form Input Labels to the Right?

Form Input Label Alignment

The goal of this article is to provide a solution for aligning form labels on the right side next to their corresponding inputs.

One possible solution involves setting a fixed width for label elements using the width property and enabling inline block display with display: inline-block. Additionally, aligning the text to the right using text-align: right ensures the labels are positioned accurately.

Here is a code snippet demonstrating this solution:

<code class="css">label {
  display: inline-block;
  width: 140px;
  text-align: right;
}</code>
Copy after login
<code class="html"><div class="block">
  <label>Simple label</label>
  <input type="text" />
</div>
<div class="block">
  <label>Label with more text</label>
  <input type="text" />
</div>
<div class="block">
  <label>Short</label>
  <input type="text" />
</div></code>
Copy after login

This method provides a simple way to align labels consistently next to inputs, enhancing the user experience and readability of forms.

The above is the detailed content of How to Align Form Input Labels to the Right?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!