Home >Web Front-end >CSS Tutorial >How to Align Form Input Labels to the Right?

How to Align Form Input Labels to the Right?

Linda Hamilton
Linda HamiltonOriginal
2024-11-06 21:29:02652browse

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>
<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>

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!

Statement:
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