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

Nginx configuration to achieve multiple server load balancing

Nginx load balancing server: IP: 192.168.0.4 (Ngi...

JavaScript manual implementation of instanceof method

1. Usage of instanceof instanceof operator is use...

Let's learn about JavaScript object-oriented

Table of contents JavaScript prototype chain Obje...

Tutorial on installing the unpacked version of mysql5.7 on CentOS 7

1. Unzip the mysql compressed package to the /usr...

Vue implements zoom in, zoom out and drag function

This article example shares the specific code of ...

Analyze the selection problem of storing time and date types in MySQL

In general applications, we use timestamp, dateti...

Semantics, writing, and best practices of link A

The semantics, writing style, and best practices ...

React handwriting tab switching problem

Parent File import React, { useState } from '...

Implementation of Nginx configuration https

Table of contents 1: Prepare https certificate 2:...

SQL implementation of LeetCode (196. Delete duplicate mailboxes)

[LeetCode] 196.Delete Duplicate Emails Write a SQ...

Example of using the href attribute and onclick event of a tag

The a tag is mainly used to implement page jump, ...

How to delete node_modules and reinstall

Table of contents Step 1: Install node_modules in...

Explanation of the precautions for Mysql master-slave replication

1. Error error connecting to master 'x@xxxx:x...

Analysis of the Principle and Method of Implementing Linux Disk Partition

remember: IDE disk: the first disk is hda, the se...