The problem of form elements and prompt text not being aligned

The problem of form elements and prompt text not being aligned

Recent projects involve the creation of a lot of forms, especially checkboxes and radio buttons. However, during the front-end development process, it was found that the single (check) box and the prompt text behind them could not be aligned without any settings, and there was a big difference between Firefox and IE. Even if vertical-align: middle is set, it still cannot be perfectly aligned. As shown in the following figure:

So I checked some websites online and found that this problem is common, as shown in the following figure (FF3.5):

In many websites that involve form pages, there is a problem that the form elements and prompt text cannot be aligned. So I decided to study this issue. First, I searched for wheatlee’s article “Everyone has their own opinions on vertical-align”. Wheatlee mentioned several key points about vertical centering in his article:

1. When vertical-align: middle is used, the center of the element is aligned with the center of the surrounding elements.

2. The definition of "center" here is: the image is of course half the height, and the text should be 0.5ex up from the baseline, that is, the center of the lowercase "x". However, many browsers often define the ex unit as 0.5em, so it is not necessarily the exact center of x (if you don’t understand terms like baseline, please read wheatlee’s article first)

Following this line of thought, and comparing it with the problem I encountered, the first thing that came to my mind was to verify whether the browser uses the same rules to render the "check box" and the image (whether it treats the check box as a square image). So write the following code:

<style>
body{font-size:12px;}
</style>
<input style="vertical-align:middle;" name="test" type="checkbox">
<img style="vertical-align:middle;" src="testpic.gif" />
Test text

The testpic.gif in the code is a black image that is exactly the same size as the check box. The display under FF3.5 is as follows:


Previous Page 1 2 3 4 Next Page Read Full Article

<<:  Priority analysis of and or queries in MySQL

>>:  Docker setting windows storage path operation

Recommend

Detailed explanation of using MySQL where

Table of contents 1. Introduction 2. Main text 2....

Detailed analysis of several situations in which MySQL indexes fail

1. Leading fuzzy query cannot use index (like ...

Node.js file copying, folder creation and other related operations

NodeJS copies the files: Generally, the copy oper...

How to connect to MySQL visualization tool Navicat

After installing Navicat The following error may ...

Use of select, distinct, and limit in MySQL

Table of contents 1. Introduction 2. select 2.1 Q...

MySQL 5.7 installation and configuration tutorial under CentOS7 64 bit

Installation environment: CentOS7 64-bit MINI ver...

Use of MySQL stress testing tool Mysqlslap

1. MySQL's own stress testing tool Mysqlslap ...

A detailed introduction to the use of block comments in HTML

Common comments in HTML: <!--XXXXXXXX-->, wh...

Basic structure of HTML documents (basic knowledge of making web pages)

HTML operation principle: 1. Local operation: ope...

Introduction to Nginx log management

Nginx log description Through access logs, you ca...

Example of how to import nginx logs into elasticsearch

The nginx logs are collected by filebeat and pass...

An article to master MySQL index query optimization skills

Preface This article summarizes some common MySQL...