一键导入
solid-styling
SolidJS styling: CSS Modules, Tailwind, Sass, Less, CSS-in-JS, global styles, component-scoped styles, class and style bindings.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
SolidJS styling: CSS Modules, Tailwind, Sass, Less, CSS-in-JS, global styles, component-scoped styles, class and style bindings.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
SolidJS advanced components: SuspenseList for coordinating multiple Suspense boundaries, NoHydration for skipping hydration of static content.
SolidJS advanced utilities: createRoot for manual disposal, createUniqueId for SSR-safe IDs, useTransition for batching async updates, observable for RxJS interop, modifyMutable for batch updates.
SolidJS control flow: Show for conditionals, Switch/Match for multiple conditions, For/Index for lists, Dynamic for dynamic components, Suspense for async data.
SolidJS advanced JSX attributes: @once for static values, attr:*/bool:*/prop:* for Web Components, textContent for text nodes, innerHTML for raw HTML.
SolidJS lifecycle: onMount for DOM access after mount, onCleanup for resource disposal, effect lifecycle management, component vs effect cleanup.
Core SolidJS primitives: signals use getter functions count(), components run once (no re-renders), effects track automatically, stores use direct property access, memos for computed values. Fine-grained reactivity means targeted DOM updates.
| name | solid-styling |
| description | SolidJS styling: CSS Modules, Tailwind, Sass, Less, CSS-in-JS, global styles, component-scoped styles, class and style bindings. |
| metadata | {"globs":["**/*.css","**/*.scss","**/*.less","**/*module.css","tailwind.config.*"]} |
Complete guide to styling SolidJS components. Choose from CSS preprocessors, CSS Modules, utility frameworks, or CSS-in-JS solutions.
import { createSignal } from "solid-js";
function Component() {
const [active, setActive] = createSignal(false);
return (
<button
class="btn"
classList={{ active: active() }}
onClick={() => setActive(!active())}
>
Click me
</button>
);
}
function Component() {
const [color, setColor] = createSignal("red");
return (
<div style={{ color: color(), "font-size": "16px" }}>
Styled content
</div>
);
}
Scoped CSS with automatic class name hashing.
// Component.module.css
.button {
padding: 10px;
background: blue;
}
.active {
background: red;
}
import styles from "./Component.module.css";
function Component() {
return (
<button class={styles.button}>
Click me
</button>
);
}
Benefits:
Utility-first CSS framework.
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
tailwind.config.js:
export default {
content: ["./src/**/*.{js,jsx,ts,tsx}"],
theme: {
extend: {},
},
plugins: [],
};
function Component() {
return (
<div class="flex items-center justify-center p-4 bg-blue-500">
<button class="px-4 py-2 bg-white rounded hover:bg-gray-100">
Click me
</button>
</div>
);
}
Features:
CSS preprocessors for advanced styling.
npm install -D sass
Component.scss:
$primary-color: blue;
.button {
padding: 10px;
background: $primary-color;
&:hover {
background: darken($primary-color, 10%);
}
}
Usage:
import "./Component.scss";
function Component() {
return <button class="button">Click me</button>;
}
npm install -D less
Component.less:
@primary-color: blue;
.button {
padding: 10px;
background: @primary-color;
}
Type-safe CSS-in-JS for Solid.
import { styled } from "@macaron-css/solid";
const Button = styled("button", {
base: {
padding: "10px",
background: "blue",
},
variants: {
size: {
small: { padding: "5px" },
large: { padding: "20px" },
},
},
});
function Component() {
return <Button size="large">Click me</Button>;
}
Atomic CSS engine.
npm install -D unocss
uno.config.ts:
import { defineConfig } from "unocss";
export default defineConfig({
// ...
});
function Component() {
return (
<div class="flex items-center p-4">
<button class="btn-primary">Click me</button>
</div>
);
}
// app.tsx or entry-client.tsx
import "./styles.css";
export default function App() {
return <div>App</div>;
}
/* styles.css */
:root {
--primary-color: blue;
--spacing: 16px;
}
.button {
background: var(--primary-color);
padding: var(--spacing);
}
import styles from "./Component.module.css";
Vite automatically handles scoped styles when using <style scoped>:
function Component() {
return (
<>
<div class="container">Content</div>
<style>{`
.container {
padding: 20px;
}
`}</style>
</>
);
}
function Component() {
const [active, setActive] = createSignal(false);
return (
<button
class="btn"
classList={{
active: active(),
disabled: !active(),
}}
>
Click me
</button>
);
}
function Component() {
const [width, setWidth] = createSignal(100);
return (
<div
style={{
width: `${width()}px`,
transition: "width 0.3s",
}}
>
Content
</div>
);
}
Choose the right solution:
Use CSS Modules for components:
Use Tailwind for utilities:
Organize styles:
Optimize for production:
/* styles.css */
[data-theme="dark"] {
--bg-color: #000;
--text-color: #fff;
}
[data-theme="light"] {
--bg-color: #fff;
--text-color: #000;
}
function Component() {
const [theme, setTheme] = createSignal("light");
return (
<div data-theme={theme()}>
<button onClick={() => setTheme(theme() === "light" ? "dark" : "light")}>
Toggle theme
</button>
</div>
);
}
Tailwind:
<div class="text-sm md:text-base lg:text-lg">
Responsive text
</div>
CSS:
.container {
padding: 10px;
}
@media (min-width: 768px) {
.container {
padding: 20px;
}
}