今天在项目中遇到radio和文字对齐问题(ie不明显,火狐和google比较明显),在此记录。html
1.浏览器默认文字大小为14px,于是当文字字体为14px时radio和checkbox与文字对齐良好,以下所示:浏览器
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <input type="radio" value="1"> 1 <input type="radio" value="2"> 2 <input type="radio" value="3"> 3 <input type="radio" value="4"> 4 <input type="radio" value="5"> 5 <input type="radio" value="6"> >5
<br/> <input type="radio" value="1"> 学生 <input type="radio" value="2"> 老师 </body> </html>
输出结果以下:字体
2.更改字体大小,对齐出现问题google
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <style> body { font-size: 12px; } </style> </head> <body> <input type="radio" value="1"> 1 <input type="radio" value="2"> 2 <input type="radio" value="3"> 3 <input type="radio" value="4"> 4 <input type="radio" value="5"> 5 <input type="radio" value="6"> >5 <br/> <input type="radio" value="1"> 学生 <input type="radio" value="2"> 老师 </body> </html>
输出结果以下:spa
若字体更改成10px或者更小对齐问题更加严重(固然字体大于14px也会出现相似问题)以下为字体为10px时code
3.解决方法htm
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <style> body { font-size: 12px; } .inputStyle { vertical-align: text-bottom; margin-bottom: 2px; *margin-bottom: -2px; //兼容IE6,IE7 } </style> </head> <body> <input type="radio" value="1" class="inputStyle"> 1 <input type="radio" value="2" class="inputStyle"> 2 <input type="radio" value="3" class="inputStyle"> 3 <input type="radio" value="4" class="inputStyle"> 4 <input type="radio" value="5" class="inputStyle"> 5 <input type="radio" value="6" class="inputStyle"> >5 <br/> <br/> <input type="radio" value="1" class="inputStyle"> 学生 <input type="radio" value="2" class="inputStyle"> 老师 </body> </html>
效果以下:blog
4.其余方法input