欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Remix如何支持原生?CSS方法詳解

 更新時間:2023年05月06日 10:31:14   作者:喬治_x  
這篇文章主要為大家介紹了Remix如何支持原生CSS的方法示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

Remix CSS 語法

Remix 是一個多頁面的框架,對頁面的原生 CSS 的支持分為兩大類型:

  • 使用 links 函數(shù),轉(zhuǎn)換成 link 標(biāo)簽支持 css
  • 使用 javascript import 語法支持 css ,但是最終也會成為 link 標(biāo)簽
  • 駝峰命名法
.PrimaryButton {
  /* ... */
}
  • html 屬性法
[data-primary-button] {
  /* ... */
}

links 函數(shù)寫法

  • rel
  • href
  • media
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)",
    },
  ];
};

links 函數(shù)層級

  • root 級, 添加全局樣式
  • 定義全局樣式
  • 在 root.tsx links 函數(shù)中添加全局樣式
import globalStylesHref from '~/styles/global.css'
export const links: LinksFunction = () => [
  { rel: "stylesheet" , href: globalStylesHref },
  ...(cssBundleHref ? [{ rel: "stylesheet", href: cssBundleHref }] : []),
];
  • route 級, 添加路由級樣式
  • 定義 route 級樣式
  • 在 routes/xxx.tsx links 函數(shù)中引入樣式
import ArticleStylesHref from "~/styles/article.css";
export const links: LinksFunction = () => [
  { rel: "stylesheet", href: ArticleStylesHref },
];
  • nest route 級,添加嵌套路由樣式
  • 理解嵌套路由(配合 <Outlet /> 使用)
  • 定義 nest route 級樣式
  • 在 routes/xxx.yyy.tsx links 函數(shù)中引入 nest 樣式
import articleDetailStylesHref from "~/styles/article.detail.css";
export const links: LinksFunction = () => [
  { rel: "stylesheet", href: articleDetailStylesHref },
];

這以文章和文章詳情作為嵌套路由,方便理解。

links 函數(shù)中 css 媒體查詢

  • media 屬性, 一般用于斷點(diǎn),暗黑模式等
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)" },
];

第三方 css

href 屬性直接訪問第三方地址:

export const links: LinksFunction = () => {
  return [
    {
      rel: "stylesheet",
      href: "https://unpkg.com/modern-css-reset@1.4.0/dist/reset.min.css",
    },
  ];
};

import 語法

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 提供的能力相當(dāng)了。

小結(jié)

  • remix 對 css 支持已經(jīng)比較成熟,市面上主流的 css 方案都正式在 v1.16.0 版本中穩(wěn)定支持。
  • remix 通過 links 韓式支持原生 css 的 link 比標(biāo)簽,設(shè)計(jì)上有一一對應(yīng)的關(guān)系。
  • 同時也支持了使用 import 語法支持,本質(zhì)是主動的加上 link 標(biāo)簽
  • 同時支持不同層級的 css 初次使用時,需要理解 root/route/nest-route 的內(nèi)容
  • remix links 頁支持了 css 的媒體查詢功能,能在 links 中定義媒體查詢斷點(diǎn)

以上就是Remix如何支持原生 CSS的詳細(xì)內(nèi)容,更多關(guān)于Remix支持原生 CSS的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • 詳解React 和 Redux的關(guān)系

    詳解React 和 Redux的關(guān)系

    這篇文章主要為大家介紹了React 和 Redux的關(guān)系,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2021-11-11
  • React router基礎(chǔ)使用方法詳解

    React router基礎(chǔ)使用方法詳解

    這篇文章主要介紹了React router基礎(chǔ)使用方法,React Router是React生態(tài)系統(tǒng)中最受歡迎的第三方庫之一,近一半的React項(xiàng)目中使用了React Router,下面就來看看如何在React項(xiàng)目中使用
    2023-04-04
  • react 報(bào)錯Module build failed: BrowserslistError: Unknown browser query `dead`問題的解決方法

    react 報(bào)錯Module build failed: Browserslis

    這篇文章主要介紹了react 報(bào)錯Module build failed: BrowserslistError: Unknown browser query `dead`問題的解決方法,需要的朋友可以參考下
    2023-06-06
  • react導(dǎo)出excel文件的四種方式

    react導(dǎo)出excel文件的四種方式

    本文主要介紹了react導(dǎo)出excel文件的四種方式,主要包括原生js導(dǎo)出,使用?js-export-excel,使用xlsx導(dǎo)出, 使用react-html-table-to-excel,感興趣的可以了解一下
    2023-11-11
  • ReactNative-JS 調(diào)用原生方法實(shí)例代碼

    ReactNative-JS 調(diào)用原生方法實(shí)例代碼

    這篇文章主要介紹了ReactNative-JS 調(diào)用原生方法實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下
    2016-10-10
  • React開啟代理的2種實(shí)用方式

    React開啟代理的2種實(shí)用方式

    最近有不少伙伴詢問react的代理配置,自己也去試驗(yàn)了一下發(fā)現(xiàn)不少的問題,在這就將所遇到的心得分享出來,這篇文章主要給大家介紹了關(guān)于React開啟代理的2種實(shí)用方式的相關(guān)資料,需要的朋友可以參考下
    2021-07-07
  • React?中在?map()?中使用條件跳出map的方法

    React?中在?map()?中使用條件跳出map的方法

    這篇文章主要介紹了React?中在?map()?中使用條件跳出map的方法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-09-09
  • React狀態(tài)提升案例介紹

    React狀態(tài)提升案例介紹

    這篇文章主要介紹了React狀態(tài)提升案例,所謂 狀態(tài)提升 就是將各個子組件的 公共state 提升到它們的父組件進(jìn)行統(tǒng)一存儲、處理,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧
    2023-04-04
  • React組件實(shí)例三大屬性state props refs使用詳解

    React組件實(shí)例三大屬性state props refs使用詳解

    這篇文章主要為大家介紹了React組件實(shí)例三大屬性state props refs使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-09-09
  • React項(xiàng)目如何使用Element的方法步驟

    React項(xiàng)目如何使用Element的方法步驟

    本文主要介紹了React項(xiàng)目如何使用Element的方法步驟,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-11-11

最新評論