Solutions to browser interpretation differences in size and width and height in CSS

Solutions to browser interpretation differences in size and width and height in CSS
Let’s look at an example first

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=gb2312″ />
<title>Untitled Document</title>
<style>
#m{height:300px;width:300px;background:#ccc}
#a{float:left;height:100px;width:100px;background:#f00;}
#b{float:left;height:100px;*height:110px;_height:120px;width:100px;background:#0f0;}
#c{clear:both;height:100px;width:100px;*width:100px;_width:120px;background:#00f;}
</style>
</head>
<body>
<div id=”m”>
<div id="a"></div>
<div id="b"></div>
<div id="c"></div>
</div>
</body>
</html>

Here, I define three heights respectively.
The first normal definition will take effect in all browsers;
The second definition adds an asterisk in front, which will be recognized as the height attribute in IE6 and IE7, but Firefox and IE8 will think it is a syntax error and ignore it. According to the order of execution, the height with an asterisk is executed in IE6 and IE7, and the first normal height is invalid (or overwritten);
The third height has an underscore in front. Only IE6 considers the underscore as a valid height attribute, while IE7, IE8 and Firefox regard the "_height" attribute as a non-existent attribute and therefore do not execute it, while IE6 executes it. In this way, the first two heights are covered by the underlined height in IE6.

Well, through this example, you should understand that if we want to set different heights of an element in different browsers, we can use the * and _ symbols to assist in the definition. At the same time, we also learned that Microsoft is a company with a high tolerance for mistakes! Haha.

However, if the first two lines of document type and namespace declarations in this example are removed, the underlined height will also be displayed normally.

The width settings are the same.

In our actual work, we will often encounter different browser interpretations of margin attributes, then asterisks and underscores can be of great help.

<<:  A brief discussion on how Tomcat breaks the parent delegation mechanism

>>:  Several ways to vertically and horizontally center in CSS3 with indefinite height and width

Recommend

About the location of the H1 tag in XHTML

There has been a lot of discussion about H1 recent...

Introduction to the properties of B-Tree

B-tree is a common data structure. Along with him...

CSS to achieve zoom in and out close button (example code)

This effect is most common on our browser page. L...

Understanding JSON (JavaScript Object Notation) in one article

Table of contents JSON appears Json structure Jso...

Detailed steps to install MySQL 5.7 via YUM on CentOS7

1. Go to the location where you want to store the...

JavaScript to achieve full screen page scrolling effect

After I finished reading JavaScript DOM, I had a ...

Steps to introduce PWA into Vue project

Table of contents 1. Install dependencies 2. Conf...

10 HTML table-related tags

In fact many people will say “I’ve seen that table...

MySQL count detailed explanation and function example code

Detailed explanation of mysql count The count fun...

How to execute PHP scheduled tasks in CentOS7

Preface This article mainly introduces the releva...