目录Remix CSS 语法links 函数写法links 函数层级links 函数中 css 媒体查询第三方 cssimport 语法小结Remix CSS 语法 Remix 是一
Remix 是一个多页面的框架,对页面的原生 CSS 的支持分为两大类型:
.PrimaryButton {
}
[data-primary-button] {
}
import type { LinksFunction } from "@remix-run/node"; // or cloudflare/deno
import globalStyleHref from '~/styles/globalStyleHref'
export const links: LinksFunction = () => {
return [
{
rel: "stylesheet",
href: globalStyleHref,
media: "(min-width: 1280px)",
},
];
};
import globalStylesHref from '~/styles/global.css'
export const links: LinksFunction = () => [
{ rel: "stylesheet" , href: globalStylesHref },
...(cssBundleHref ? [{ rel: "stylesheet", href: cssBundleHref }] : []),
];
import ArticleStylesHref from "~/styles/article.css";
export const links: LinksFunction = () => [
{ rel: "stylesheet", href: ArticleStylesHref },
];
<Outlet />
使用)import articleDetailStylesHref from "~/styles/article.detail.css";
export const links: LinksFunction = () => [
{ rel: "stylesheet", href: articleDetailStylesHref },
];
这以文章和文章详情作为嵌套路由,方便理解。
export const links: LinksFunction = () => {
return [
{
rel: "stylesheet",
href: mainStyles,
},
{
rel: "stylesheet",
href: largeStyles,
media: "(min-width: 1024px)",
},
{
rel: "stylesheet",
href: xlStyles,
media: "(min-width: 1280px)",
}
];
};
import ArticleStylesHref from "~/styles/article.css";
import Article1024StylesHref from '~/styles/article-1024.css'
import Article1208StylesHref from '~/styles/article-1280.css'
export const links: LinksFunction = () => [
{ rel: "stylesheet", href: ArticleStylesHref },
{ rel: "stylesheet", href: Article1024StylesHref, media: "(min-width: 1024px)", },
{ rel: "stylesheet", href: Article1208StylesHref, media: "(min-width: 1280px)" },
];
href 属性直接访问第三方地址:
export const links: LinksFunction = () => {
return [
{
rel: "stylesheet",
href: "https://unpkg.com/modern-css-reset@1.4.0/dist/reset.min.css",
},
];
};
import 语法需要配合 remix 提供的 @remix-run/css-bundle
包使用:
import { cssBundleHref } from "@remix-run/css-bundle";
export const links: LinksFunction = () => [
...(cssBundleHref ? [{ rel: "stylesheet", href: cssBundleHref }] : []),
];
此时就可以直接使用 import './xxx.css'
文件,这与 webpack css-loader 提供的能力相当了。
以上就是Remix如何支持原生 CSS的详细内容,更多关于Remix支持原生 CSS的资料请关注编程网其它相关文章!
--结束END--
本文标题: Remix如何支持原生 CSS方法详解
本文链接: https://www.lsjlt.com/news/212679.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-01-12
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0