Home >Web Front-end >CSS Tutorial >How to Achieve Consistent Checkbox and Label Alignment Across Browsers?

How to Achieve Consistent Checkbox and Label Alignment Across Browsers?

DDD
DDDOriginal
2024-12-21 12:25:16456browse

How to Achieve Consistent Checkbox and Label Alignment Across Browsers?

How to Align Checkboxes and Their Labels Consistently Cross-Browsers

This question highlights the challenges faced in aligning checkboxes and their labels consistently across different browsers, particularly Safari, Firefox, and IE. The provided code showcases the standard HTML and CSS for a form containing a checkbox and its label.

One solution that was once popular involved using vertical-align: baseline on the input to align the checkbox correctly in Safari. However, this approach often resulted in misalignments in Firefox and IE.

After extensive testing and tweaking, a different solution emerged, which involves the following CSS properties:

label {
  display: block;
  padding-left: 15px;
  text-indent: -15px;
}
input {
  width: 13px;
  height: 13px;
  padding: 0;
  margin: 0;
  vertical-align: bottom;
  position: relative;
  top: -1px;
  *overflow: hidden;
}

This solution aligns the checkbox and its label on separate lines and ensures vertical alignment regardless of the browser. It also indents the label text correctly after wrapping. With this approach, checkboxes and their labels can be consistently aligned cross-browsers.

The above is the detailed content of How to Achieve Consistent Checkbox and Label Alignment Across Browsers?. 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