css link @import

本文介绍了如何使用@import导入CSS文件以及如何通过JavaScript修改页面背景颜色。探讨了@import与link标签的区别,尤其是在加载时机上的不同,以及@import在实际应用中可能带来的额外HTTP请求等问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

if you use in html :

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
    @import url("css1.css");
    </style>
</head>
<body>

    <script>

        document.querySelector('body').setAttribute('background','red');

    </script>
</body>
</html>

or in other css file

//css2.css
@import "css1.css";
//css1.css
body{
    background: green;
}

Note:
.1 In some case , @import is the same to link , but @import will load after the document render , so maybe short white time , when use @import .

.2 Use @import can make css module , but use @import “css1.css” in css2.css will cause two http request :

.3 when you use @import xx.css in sass file you after compile will get same file like @import url(‘xx.css’) but compile the css code to the file that use import.

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值