Home Web Front-end HTML Tutorial div css browser compatibility and understanding of css hack_html/css_WEB-ITnose

div css browser compatibility and understanding of css hack_html/css_WEB-ITnose

Jun 24, 2016 pm 12:30 PM

After writing div css code for so long, I really don’t know what this hack is? I checked online carefully. Simply put, the process of writing different CSS codes for different browsers is called CSS hack, also called writing CSS hack.

Principle of CSS hack: Because different browsers have different support and parsing results for CSS, and also due to the priority relationship in CSS. We can use this to write different CSS for different browsers.

For example, IE6 can recognize underline "_" and asterisk "*", IE7 can recognize asterisk "*", but cannot recognize underline "_", and firefox cannot recognize both. Wait

The writing order is generally to write the CSS of browsers with strong recognition capabilities at the end

Browser priority level: FF < IE7 < IE6, CSS hack writing order is generally FF IE7 IE6

Let’s take a look at the following examples of div css browser compatibility:

#demo {width:100px;} /* Executed by FIREFOX, IE6, IE7.*/

* html #demo {width:120px;} /* will be executed by IE6, and the previous definition will be overwritten by the later one, so the width of #demo will be 120px in IE6; */

* html # demo {width:130px;} /* will be executed by IE7*/

So in the end, the width of #demo is interpreted by the three browsers as:

firefox:100px;

ie6:120px;

ie7:130px;

The above example can also be solved using the method in my previous article "div css browser compatibility!" No more examples. ”

div css browser compatibility tips:

① Vertically centered. Set line-height to the same height as the current div, and then pass vertical-align: middle.( Be careful not to wrap the content.)

② Center horizontally. margin: 0 auto; (Of course it is not a panacea)
③ If you need to add styles to the content in the a tag, you need to set display: block; (common in Navigation tag)
④ The difference in understanding of BOX between FF and IE leads to a 2px difference. There are also problems such as the margin of a div set to float being doubled under IE.
⑤ The ul tag under FF has list-style and padding by default. . It is best to declare it in advance to avoid unnecessary trouble. (Common in navigation tags and content lists)

⑥ Do not set the height of the div as an external wrapper. It is best to add overflow: hidden. to achieve the goal. Height adaptive.

⑦ Regarding the hand cursor. cursor: pointer. And hand is only applicable to IE.

⑧ Setting padding on div under FF will cause the width and height to increase, but IE does not Yes. (can be solved with !important)

Note: Most of the css styles for firefox IE6 and IE7
are now hacked with !important. For IE6 and firefox tests, it can be displayed normally,
but IE7 !important can be interpreted correctly, but it will cause the page not to be displayed as required! Find a pin
A good hack for IE7 is to use "*html". Now browse it with IE7 and there should be no problem.


Now write a browser compatible one:
#cshk{ height:20px; } /* Moz */
* html #cshk {height:50px; } /* IE6 */
* html #cshk {height:80px; } /* IE7 */
Then the height under firefox is 20, the height under IE6 is 50, and the height under IE7 is 80.

Let me give you some advice: Is it better to use CSS Hack or not? In fact, when designing a website, it would be best if you can consider some possible places where CSS bugs may occur. I try to avoid CSS bugs when designing a website. Most experts don’t use hacks.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the purpose of the <progress> element? What is the purpose of the <progress> element? Mar 21, 2025 pm 12:34 PM

The article discusses the HTML &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

What is the purpose of the <datalist> element? What is the purpose of the <datalist> element? Mar 21, 2025 pm 12:33 PM

The article discusses the HTML &lt;datalist&gt; element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What is the viewport meta tag? Why is it important for responsive design? What is the viewport meta tag? Why is it important for responsive design? Mar 20, 2025 pm 05:56 PM

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

What is the purpose of the <iframe> tag? What are the security considerations when using it? What is the purpose of the <iframe> tag? What are the security considerations when using it? Mar 20, 2025 pm 06:05 PM

The article discusses the &lt;iframe&gt; tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

What is the purpose of the <meter> element? What is the purpose of the <meter> element? Mar 21, 2025 pm 12:35 PM

The article discusses the HTML &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

See all articles