We know that the properties of the select tag in each browser and the support of each browser are somewhat different, which causes the display of the select box in each browser to be different. Next, we will create a fully compatible select by supporting the main appearance CSS properties. I wrote a DEMO for the select's height, padding, and line-height using the control variable method to test three situations on various browsers: height.100.padding.0, height.no.padding.100, no.height.no.padding. The results are shown in the linked images. The DEMO appearance of each browser ![]() We can derive the following research properties.
Through the above research results attribute summary, we know that IE6 has a fixed height of 22px no matter how it is set, and other browsers except Safari support the height attribute, so we set height:22px. Now let's correct the Safari browser. We found that only Safari supports the line-height attribute, so we can use line-height to correct its height to 22px. Under the premise of font-size being 12px, we set line-height:22px. Finally, the text in FF and IE9 is not centered. We set padding:2px 0 for it. We found that FF and IE9 are centered, but the height of the selects in each browser has not increased. So here is a question. When the height is set, the padding of a small number does not increase the overall height? The following is a fully compatible code example. Copy code The code is as follows:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>demo</title> <style> *{padding:0; margin:0} body{font-size:12px} select{height:22px; line-height:18px; padding:2px 0} </style> </head> <body> <div style="margin-top:20px; margin-left:20px; background:#000"> <select> <option>Demonstration Question 1</option> <option>Demonstration Question 2</option> <option>Demonstration Question 3</option> <option>Demonstration Question 4</option> <option>Demonstration Question 5</option> </select> </div> </body> </html> |
<<: Using text shadow and element shadow effects in CSS
>>: How many times will multiple setStates in React be called?
1. The difference between TEXT and BLOB The only ...
[LeetCode] 185. Department Top Three Salaries The...
Preface Since vue3.0 was officially launched, man...
Table of contents 1. charAt grammar parameter ind...
Table of contents Scenario Try to solve solve Sce...
background Recently, a leader wanted us to build ...
Table of contents Overview Code Implementation Si...
1. Environmental preparation: Operating system: C...
This article is based on the Free Code Camp Basic...
Table of contents Preface 1. Download MySQL 8.0.2...
Remax is an open source framework developed by An...
This article shares with you how to use Vue to im...
Convert code to image using html2canvas is a very...
Azure Container Registry is a managed, dedicated ...
Table of contents Preface Create a Vite project R...