跳至主要內容

自訂 CSS

如果我們的 UI 微調 無法完全符合你的品牌,請使用自訂 CSS 來調整你的登入體驗。只需將你的 CSS 代碼添加到我們的編輯器中,即可立即查看變更。

Logto Console 中的自訂 CSS

  1. 前往 Console > Sign-in experience > Branding > Custom CSS
  2. 在左側編輯器中編輯 CSS 代碼,右側預覽模態會立即呈現變更。注意:代碼編輯器目前僅支援 CSS 代碼,不支援 HTML 或 Javascript。
  3. 儲存變更。
  4. 別忘了點擊「即時預覽」按鈕以檢查所有頁面的變更。

若要查看 Logto 的元件化介面設計,你可以瀏覽 GitHub 上的 Logto/packages/experience/src 或在 Logto 即時預覽頁面上開啟瀏覽器的「檢查元素」工具。

範例

例如,如果你想讓你的登入頁面在網頁視圖中呈現 夜城 的感覺,可以嘗試以下 CSS:

@font-face {
font-family: 'Rock Salt';
font-style: normal;
font-weight: normal;
font-display: swap;
src: url('https://fonts.gstatic.com/s/rocksalt/v18/MwQ0bhv11fWD6QsAVOZrt0M6p7NGrQ.woff2')
format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F,
U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
font-family: 'Share Tech';
font-style: normal;
font-weight: normal;
font-display: swap;
src: url('https://fonts.gstatic.com/s/sharetech/v17/7cHtv4Uyi5K0OeZ7bohU8H0JmBUhfrE.woff2')
format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F,
U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

#app * {
font-family: 'Share Tech';
letter-spacing: 0.5px;
--color-type-primary: #ffffff;
--color-type-secondary: #c9c5d0;
}

#app > div[class$='viewBox'] {
background-image: url('https://silverhand.io/assets/v-in-nc.jpg');
background-size: cover;
}

#app main[class*='main'] {
background-image: url('https://logtoeu.blob.core.windows.net/public-blobs/g3cp4y/m-g3cp4y/2024/01/02/w9j0x57g/gentle-universe.png');
background-size: cover;
opacity: 97%;
min-height: initial;
padding: 24px;
padding-bottom: 72px;
border-radius: 12px;
}

#app main[class*='main'] img[class*='logo'] {
content: url('https://silverhand.io/assets/cyberpunk-2077.png');
margin: -20px 0 -12px;
height: 160px;
}

#app form div[class*='inputField'] > div {
outline: none;
border: none;
border-radius: 4px;
}

#app form div[class*='inputField'] input,
#app form div[class*='inputField'] div[class$='countryCodeSelector'] {
background: initial;
background-color: #564f7c;
font-family: 'Share Tech';
letter-spacing: 0.5px;
font-size: 16px;
font-weight: 600;
}

#app form div[class*='inputField'] > div > input::placeholder,
#app main[class*='main'] > div[class*='wrapper'] > div[class*='divider'],
#app main[class*='main'] > div[class*='wrapper'] > form div[class*='content'],
#app main[class*='main'] > div[class*='wrapper'] > form div[class*='content'] > span {
color: #a7a5b3;
}

#app main[class*='main'] > div[class*='wrapper'] > div[class*='divider'] > i[class*='line'],
#app
main[class*='main']
> div[class*='wrapper']
> div[class*='terms']
> i[class*='divider']::after {
background: rgba(247, 248, 248, 14%);
}

#app button {
font-weight: 600;
font-size: 16px;
border-radius: 4px;
}

#app button[type='submit'] {
background: linear-gradient(270.84deg, #2fd6fb -24.55%, #6369fc 44.33%, #a741eb 119.2%), #5d34f2;
}

#app div[class*='socialLinkList'] *,
#app div[class*='main'] * {
font-family: 'Share Tech';
}

#app main[class*='main'] > div[class*='wrapper'] > div[class*='createAccount'] {
font-family: 'Share Tech';
color: #ffffff;
}

#app div[class*='socialLinkList'] > button {
border: none;
background-color: #645995;
}
Logto 自訂 CSS 使用案例
備註:

由於 Logto 使用 CSS 模組,你可能會在 DOM 元素的 class 屬性中看到雜湊值(例如,<div>vUugRG_container)。要覆蓋這些,你可以使用 $= CSS 選擇器來匹配以指定值結尾的元素。在此情況下,應為 div[class$=container]

使用 Management API 的自訂 CSS

你也可以使用 Management APIPATCH /api/sign-in-exp,並在主體中包含 { "customCss": "arbitrary string" } 來設定登入體驗的自訂 CSS。你應該會看到 customCss 的值附加在頁面的 <title> 之後。如果樣式具有更高的優先級,應該能夠覆蓋。