Home > Web Front-end > CSS Tutorial > How to Align Radio Buttons and Labels Horizontally in Forms?

How to Align Radio Buttons and Labels Horizontally in Forms?

Susan Sarandon
Release: 2024-11-04 06:05:28
Original
876 people have browsed it

How to Align Radio Buttons and Labels Horizontally in Forms?

Radio Buttons and Labels Aligned Horizontally

When creating forms, it can be frustrating to have labels and radio buttons appear on different lines. To resolve this issue and keep them aligned horizontally:

Solution:

Float the labels and radio buttons to the left and adjust padding and margins as necessary. Additionally, assign a class name to the radio buttons for older versions of Internet Explorer. To achieve identical inline alignment for all buttons, use the following HTML structure:

<code class="html"><fieldset>
  <div class="some-class">
    <input type="radio" class="radio" name="x" value="y" id="y">
    <label for="y">Thing 1</label>
    <input type="radio" class="radio" name="x" value="z" id="z">
    <label for="z">Thing 2</label>
  </div>
</fieldset></code>
Copy after login
<code class="css">fieldset {
  overflow: hidden;
}

.some-class {
  float: left;
  clear: none;
}

label {
  float: left;
  clear: none;
  display: block;
  padding: 0px 1em 0px 8px;
}

input[type=radio],
input.radio {
  float: left;
  clear: none;
  margin: 2px 0 0 2px;
}</code>
Copy after login

By following these guidelines, you can ensure that labels and radio buttons appear on the same line, providing a seamless user experience for filling out forms.

The above is the detailed content of How to Align Radio Buttons and Labels Horizontally in Forms?. 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