1.!important能将当前的CSS代码优先级提升为最高
1.1
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> div{ width:100px; height:100px; background-color:blue !important; } </style> </head> <body> <div style="background-color:red"> </div> </body> </html>
1.2
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> div{ width:100px; height:100px; background-color:blue !important; background-color:red; } </style> </head> <body> <div > </div> </body> </html>
但是在IE <=6中这样设置是无效的,需要这样
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> div{ width:100px; height:100px; background-color:blue !important; } div{ background-color:red; } </style> </head> <body> <div > </div> </body> </html>
[email protected]的作用类似于link标签,都是将外部CSS代码导入
2.1在style标签中使用
<style> @import "1.css" </style>
2.2在css文件中使用
div{ width:100px; height:100px; } @import "2.css";
时间: 2024-10-11 10:36:53