Home > Web Front-end > CSS Tutorial > What are the ways to write CSS that are compatible with IE?

What are the ways to write CSS that are compatible with IE?

醉折花枝作酒筹
Release: 2023-01-06 11:16:02
Original
3466 people have browsed it

The CSS writing methods compatible with IE are: 1. Add "-" or "_" in front of the attribute, and the writing method is "_attribute: attribute value"; 2. CSS conditional comments, the syntax "".

What are the ways to write CSS that are compatible with IE?

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

1. Hack

Writing method:

.demo {
margin-left:30px; 
_margin-left:20px; 
}
Copy after login

Advantages:

1. Embedded in CSS, it is very convenient when writing

2. Embedded in CSS, it will not generate more HTTP requests

Disadvantages:

1. Not unified in one module, later maintenance and modification will be troublesome

2. Even if this writing method does not work, the browser will load the code and waste resources

2. CSS conditional comments

Writing method:

<!--[if IE 6 ]>
    <link rel="stylesheet" type="text/css" media="all" href="./ie6.css" />
<![endif]-->
Copy after login

Advantages :

1. The code is independent, which is beneficial to later maintenance

2. For browsers where the code does not work, this code is just an ordinary comment and will not be loaded when they load it. Load its content and save resources

Disadvantages:

1. A new HTTP request is added, which undoubtedly increases the pressure on the old version of IE browser.

Extension:

HTML tag conditional comments

<!DOCTYPE html>   
<!--[if IE 6 ]> <html class="ie6 lte_ie6 lte_ie7 lte_ie8" lang="zh-CN"> <![endif]-->
<!--[if lte IE 6 ]> <html class="lte_ie6 lte_ie7 lte_ie8" lang="zh-CN"> <![endif]-->
<!--[if lte IE 7 ]> <html class="lte_ie7 lte_ie8" lang="zh-CN"> <![endif]-->
<!--[if lte IE 8 ]> <html class="lte_ie8" lang="zh-CN"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--><html lang="zh-CN"><!--<![endif]-->
Copy after login
.ie6 .demo {  
    margin-left: 20px;
      }
Copy after login

This method can separate the code into a separate module and will not add a new HTTP request. Currently used more.

Recommended learning: css video tutorial

The above is the detailed content of What are the ways to write CSS that are compatible with IE?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template