Home  >  Article  >  Web Front-end  >  How to Resolve Label Text Indentation Inconsistency in Forms with Space Constraints?

How to Resolve Label Text Indentation Inconsistency in Forms with Space Constraints?

Linda Hamilton
Linda HamiltonOriginal
2024-10-24 07:44:02181browse

How to Resolve Label Text Indentation Inconsistency in Forms with Space Constraints?

Fixing Label Text Indentation Issues in a Constrained Form

When working with forms in limited-width scenarios, labels with lengthy text may wrap to multiple lines. However, the indentation on the second line can be inconsistent with the first, leading to an untidy appearance.

To address this visual disparity, CSS can be employed to achieve uniform indentation across all lines.

Solution:

The provided code snippet offers a solution that addresses the indentation issue:

<code class="css">.checkbox-field {
    display: flex;
    flex-direction: row;
}

.checkbox-field label {
    margin-left: auto;
}</code>
<code class="html"><div class="checkbox-field">
    <input type="checkbox" id="check">
    <label for="check">Field 2 Label, may be longer than normal, This is an example for this lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem lorem</label>
</div></code>

This solution utilizes the flex-direction: row property to align the label element next to the input element. Additionally, the margin-left: auto property automatically adjusts the label's indentation to match that of the input, regardless of the text length.

The above is the detailed content of How to Resolve Label Text Indentation Inconsistency in Forms with Space Constraints?. 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