You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无需使用NPM,如何在Web项目中使用Material Design 3?

无需使用NPM,如何在Web项目中使用Material Design 3?

嘿,我完全懂你的处境——拿着被管理员锁定的Chromebook,没法用NPM来构建Material Design 3,之前一直用MDL 1.3,现在想升级却卡壳了对吧?别发愁,咱们直接用CDN引入MD3的资源就行,完全不需要本地构建,步骤超简单:

  • 第一步,先把你原来项目里的Material Design Lite 1.3资源链接删掉,就是这几段:

    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
    <link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.orange-yellow.min.css">
    <script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
    
  • 第二步,引入Material Design 3的CDN资源,把下面这些代码放到你的HTML头部(<head>标签里)和尾部(</body>标签前):
    样式文件(放在<head>里):

    <!-- 引入Roboto字体,MD3的默认字体 -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap">
    <!-- 引入Material Icons图标 -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
    <!-- 引入MD3核心样式 -->
    <link rel="stylesheet" href="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.css">
    

    脚本文件(放在</body>标签前):

    <!-- 引入MD3核心脚本 -->
    <script src="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.js"></script>
    
  • 第三步,接下来你就可以直接按照MD3的组件规范来使用各种UI元素了,比如按钮、卡片、文本框这些。和之前MDL的用法有一些细节差异,但因为是CDN直接引入,不需要任何打包构建操作,刚好适配你没法用NPM的Chromebook环境。

如果你想要更稳定的版本,也可以把代码里的latest换成具体的版本号(比如11.0.0),这样能避免最新版本的兼容性问题。

备注:内容来源于stack exchange,提问作者Bynet Official

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.20 09:58:00