{"id":1971,"date":"2025-03-10T09:23:27","date_gmt":"2025-03-10T01:23:27","guid":{"rendered":"https:\/\/www.fanyamin.com\/wordpress\/?p=1971"},"modified":"2025-03-10T09:23:27","modified_gmt":"2025-03-10T01:23:27","slug":"tailwind-css-framework","status":"publish","type":"post","link":"https:\/\/www.fanyamin.com\/wordpress\/?p=1971","title":{"rendered":"Tailwind CSS framework"},"content":{"rendered":"<h1>Tailwind CSS framework<\/h1>\n<h2>Tailwind CSS \u6846\u67b6\u4ecb\u7ecd<\/h2>\n<p>Tailwind CSS \u662f\u4e00\u4e2a\u529f\u80fd\u7c7b\uff08utility-first\uff09\u7684 CSS \u6846\u67b6\uff0c\u5b83\u63d0\u4f9b\u4e86\u5927\u91cf\u7684\u4f4e\u7ea7\u5b9e\u7528\u7c7b\uff0c\u8ba9\u5f00\u53d1\u8005\u53ef\u4ee5\u76f4\u63a5\u5728 HTML \u4ee3\u7801\u4e2d\u7f16\u5199\u6837\u5f0f\uff0c\u800c\u65e0\u9700\u521b\u5efa\u81ea\u5b9a\u4e49\u7684 CSS \u89c4\u5219\u3002\u5b83\u7684\u8bbe\u8ba1\u7406\u5ff5\u662f\u901a\u8fc7\u7ec4\u5408\u8fd9\u4e9b\u5c0f\u578b\u7684\u6837\u5f0f\u7c7b\u6765\u5feb\u901f\u6784\u5efa UI\uff0c\u800c\u4e0d\u662f\u50cf\u4f20\u7edf CSS \u90a3\u6837\u4f9d\u8d56\u9884\u5b9a\u4e49\u7684\u7ec4\u4ef6\u6216\u5168\u5c40\u6837\u5f0f\u3002<\/p>\n<h3><strong>Tailwind CSS \u7684\u7279\u70b9<\/strong><\/h3>\n<ol>\n<li><strong>\u529f\u80fd\u7c7b\u4f18\u5148<\/strong>\uff1a\u4f7f\u7528\u539f\u5b50\u7c7b\uff08\u5982 <code>p-4<\/code>\u3001<code>text-center<\/code>\u3001<code>bg-blue-500<\/code>\uff09\u5feb\u901f\u6784\u5efa UI\u3002<\/li>\n<li><strong>\u9ad8\u5ea6\u53ef\u5b9a\u5236<\/strong>\uff1a\u53ef\u4ee5\u901a\u8fc7 <code>tailwind.config.js<\/code> \u8fdb\u884c\u914d\u7f6e\uff0c\u8c03\u6574\u989c\u8272\u3001\u5b57\u4f53\u3001\u95f4\u8ddd\u7b49\u3002<\/li>\n<li><strong>\u65e0\u9700\u989d\u5916 CSS \u6587\u4ef6<\/strong>\uff1a\u6240\u6709\u6837\u5f0f\u76f4\u63a5\u5728 HTML \u6587\u4ef6\u4e2d\u5b9a\u4e49\uff0c\u51cf\u5c11\u4e86 CSS \u4ee3\u7801\u91cf\u3002<\/li>\n<li><strong>\u54cd\u5e94\u5f0f\u8bbe\u8ba1<\/strong>\uff1a\u5185\u7f6e <code>sm<\/code>\u3001<code>md<\/code>\u3001<code>lg<\/code>\u3001<code>xl<\/code> \u7b49\u65ad\u70b9\u7c7b\uff0c\u65b9\u4fbf\u9002\u914d\u4e0d\u540c\u8bbe\u5907\u3002<\/li>\n<li><strong>Dark Mode \u652f\u6301<\/strong>\uff1a\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u6697\u9ed1\u6a21\u5f0f\u3002<\/li>\n<\/ol>\n<hr \/>\n<h2><strong>\u5b89\u88c5 Tailwind CSS<\/strong><\/h2>\n<p>\u53ef\u4ee5\u901a\u8fc7 npm \u5b89\u88c5 Tailwind CSS\uff1a<\/p>\n<pre><code class=\"language-sh\">npm install -D tailwindcss postcss autoprefixer\nnpx tailwindcss init<\/code><\/pre>\n<p>\u5728 <code>tailwind.config.js<\/code> \u4e2d\u914d\u7f6e\uff1a<\/p>\n<pre><code class=\"language-js\">module.exports = {\n  content: [&quot;.\/src\/**\/*.{html,js}&quot;], \/\/ \u76d1\u89c6\u7684\u6587\u4ef6\u8def\u5f84\n  theme: {\n    extend: {}, \/\/ \u53ef\u81ea\u5b9a\u4e49\u6269\u5c55\u6837\u5f0f\n  },\n  plugins: [],\n};<\/code><\/pre>\n<p>\u7136\u540e\uff0c\u5728 CSS \u6587\u4ef6\u4e2d\u5f15\u5165 Tailwind\uff1a<\/p>\n<pre><code class=\"language-css\">@tailwind base;\n@tailwind components;\n@tailwind utilities;<\/code><\/pre>\n<hr \/>\n<h2><strong>Tailwind CSS \u7528\u6cd5\u793a\u4f8b<\/strong><\/h2>\n<h3><strong>1. \u57fa\u7840\u6837\u5f0f<\/strong><\/h3>\n<pre><code class=\"language-html\">&lt;button class=&quot;bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-700&quot;&gt;\n  \u70b9\u51fb\u6211\n&lt;\/button&gt;<\/code><\/pre>\n<p><strong>\u89e3\u6790<\/strong>\uff1a<\/p>\n<ul>\n<li><code>bg-blue-500<\/code>\uff1a\u8bbe\u7f6e\u80cc\u666f\u989c\u8272\u4e3a\u84dd\u8272\uff08\u5f3a\u5ea6 500\uff09\u3002<\/li>\n<li><code>text-white<\/code>\uff1a\u6587\u672c\u989c\u8272\u4e3a\u767d\u8272\u3002<\/li>\n<li><code>px-4 py-2<\/code>\uff1a\u5de6\u53f3\u586b\u5145 16px\uff084<em>4px\uff09\uff0c\u4e0a\u4e0b\u586b\u5145 8px\uff082<\/em>4px\uff09\u3002<\/li>\n<li><code>rounded<\/code>\uff1a\u4f7f\u6309\u94ae\u56db\u89d2\u53d8\u5706\u3002<\/li>\n<li><code>hover:bg-blue-700<\/code>\uff1a\u9f20\u6807\u60ac\u505c\u65f6\u80cc\u666f\u989c\u8272\u53d8\u6df1\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3><strong>2. \u54cd\u5e94\u5f0f\u8bbe\u8ba1<\/strong><\/h3>\n<pre><code class=\"language-html\">&lt;div class=&quot;w-full md:w-1\/2 lg:w-1\/3 bg-gray-200 p-4&quot;&gt;\n  \u8fd9\u4e2a div \u5728\u5c0f\u5c4f\u5e55\u5360\u6ee1\u5168\u5bbd\uff0c\u5728\u4e2d\u7b49\u5c4f\u5e55\u5360\u4e00\u534a\uff0c\u5728\u5927\u5c4f\u5e55\u5360\u4e09\u5206\u4e4b\u4e00\u3002\n&lt;\/div&gt;<\/code><\/pre>\n<p><strong>\u89e3\u6790<\/strong>\uff1a<\/p>\n<ul>\n<li><code>w-full<\/code>\uff1a\u9ed8\u8ba4\u5728\u5c0f\u5c4f\u5e55\u4e0b\u5360\u6ee1\u6574\u4e2a\u5bbd\u5ea6\u3002<\/li>\n<li><code>md:w-1\/2<\/code>\uff1a\u5728 <code>md<\/code>\uff08\u4e2d\u7b49\u5c4f\u5e55\uff0c<code>768px<\/code> \u53ca\u4ee5\u4e0a\uff09\u65f6\u5bbd\u5ea6\u4e3a <code>1\/2<\/code>\u3002<\/li>\n<li><code>lg:w-1\/3<\/code>\uff1a\u5728 <code>lg<\/code>\uff08\u5927\u5c4f\u5e55\uff0c<code>1024px<\/code> \u53ca\u4ee5\u4e0a\uff09\u65f6\u5bbd\u5ea6\u4e3a <code>1\/3<\/code>\u3002<\/li>\n<li><code>bg-gray-200<\/code>\uff1a\u80cc\u666f\u989c\u8272\u4e3a\u6d45\u7070\u8272\u3002<\/li>\n<li><code>p-4<\/code>\uff1a\u6dfb\u52a0 16px \u5185\u8fb9\u8ddd\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3><strong>3. Flexbox \u5e03\u5c40<\/strong><\/h3>\n<pre><code class=\"language-html\">&lt;div class=&quot;flex justify-between items-center bg-gray-100 p-4&quot;&gt;\n  &lt;div class=&quot;text-xl font-bold&quot;&gt;Logo&lt;\/div&gt;\n  &lt;nav class=&quot;space-x-4&quot;&gt;\n    &lt;a href=&quot;#&quot; class=&quot;text-blue-500 hover:underline&quot;&gt;\u9996\u9875&lt;\/a&gt;\n    &lt;a href=&quot;#&quot; class=&quot;text-blue-500 hover:underline&quot;&gt;\u5173\u4e8e&lt;\/a&gt;\n    &lt;a href=&quot;#&quot; class=&quot;text-blue-500 hover:underline&quot;&gt;\u8054\u7cfb&lt;\/a&gt;\n  &lt;\/nav&gt;\n&lt;\/div&gt;<\/code><\/pre>\n<p><strong>\u89e3\u6790<\/strong>\uff1a<\/p>\n<ul>\n<li><code>flex<\/code>\uff1a\u542f\u7528 Flexbox \u5e03\u5c40\u3002<\/li>\n<li><code>justify-between<\/code>\uff1a\u8ba9\u5b50\u5143\u7d20\u5728\u4e3b\u8f74\u65b9\u5411\u4e0a\u5747\u5300\u5206\u5e03\uff0c\u4e24\u7aef\u5bf9\u9f50\u3002<\/li>\n<li><code>items-center<\/code>\uff1a\u5728\u4ea4\u53c9\u8f74\u4e0a\u5c45\u4e2d\u5bf9\u9f50\u3002<\/li>\n<li><code>space-x-4<\/code>\uff1a\u5bfc\u822a\u94fe\u63a5\u4e4b\u95f4\u6709 16px\uff084\u00d74px\uff09\u95f4\u8ddd\u3002<\/li>\n<li><code>hover:underline<\/code>\uff1a\u9f20\u6807\u60ac\u505c\u65f6\u6dfb\u52a0\u4e0b\u5212\u7ebf\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3><strong>4. \u7f51\u683c\u5e03\u5c40<\/strong><\/h3>\n<pre><code class=\"language-html\">&lt;div class=&quot;grid grid-cols-3 gap-4&quot;&gt;\n  &lt;div class=&quot;bg-red-500 h-20&quot;&gt;&lt;\/div&gt;\n  &lt;div class=&quot;bg-green-500 h-20&quot;&gt;&lt;\/div&gt;\n  &lt;div class=&quot;bg-blue-500 h-20&quot;&gt;&lt;\/div&gt;\n&lt;\/div&gt;<\/code><\/pre>\n<p><strong>\u89e3\u6790<\/strong>\uff1a<\/p>\n<ul>\n<li><code>grid<\/code>\uff1a\u542f\u7528\u7f51\u683c\u5e03\u5c40\u3002<\/li>\n<li><code>grid-cols-3<\/code>\uff1a\u8bbe\u7f6e 3 \u5217\u5e03\u5c40\u3002<\/li>\n<li><code>gap-4<\/code>\uff1a\u7f51\u683c\u95f4\u8ddd\u4e3a 16px\uff084\u00d74px\uff09\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3><strong>5. \u6df1\u8272\u6a21\u5f0f<\/strong><\/h3>\n<pre><code class=\"language-html\">&lt;div class=&quot;bg-white dark:bg-gray-800 text-black dark:text-white p-4&quot;&gt;\n  \u6df1\u8272\u6a21\u5f0f\u793a\u4f8b\n&lt;\/div&gt;<\/code><\/pre>\n<p><strong>\u89e3\u6790<\/strong>\uff1a<\/p>\n<ul>\n<li><code>dark:bg-gray-800<\/code>\uff1a\u5728\u6df1\u8272\u6a21\u5f0f\u4e0b\uff0c\u80cc\u666f\u989c\u8272\u53d8\u4e3a\u6df1\u7070\u8272\u3002<\/li>\n<li><code>dark:text-white<\/code>\uff1a\u5728\u6df1\u8272\u6a21\u5f0f\u4e0b\uff0c\u6587\u672c\u989c\u8272\u53d8\u4e3a\u767d\u8272\u3002<\/li>\n<\/ul>\n<p>\u8981\u542f\u7528\u6df1\u8272\u6a21\u5f0f\uff0c\u53ef\u4ee5\u5728 <code>tailwind.config.js<\/code> \u4e2d\u6dfb\u52a0\uff1a<\/p>\n<pre><code class=\"language-js\">module.exports = {\n  darkMode: &#039;class&#039;, \/\/ \u624b\u52a8\u5207\u6362\u6df1\u8272\u6a21\u5f0f\n};<\/code><\/pre>\n<p>\u7136\u540e\uff0c\u5728 HTML \u9875\u9762\u4e2d\uff1a<\/p>\n<pre><code class=\"language-js\">document.documentElement.classList.toggle(&#039;dark&#039;);<\/code><\/pre>\n<hr \/>\n<h2><strong>\u603b\u7ed3<\/strong><\/h2>\n<p>Tailwind CSS \u901a\u8fc7\u63d0\u4f9b\u5927\u91cf\u7684\u5b9e\u7528\u7c7b\uff0c\u4f7f\u5f00\u53d1\u8005\u80fd\u5feb\u901f\u6784\u5efa\u9875\u9762\uff0c\u800c\u65e0\u9700\u624b\u5199\u590d\u6742\u7684 CSS\u3002\u5b83\u7684\u54cd\u5e94\u5f0f\u8bbe\u8ba1\u3001\u7075\u6d3b\u7684\u914d\u7f6e\u4ee5\u53ca\u5f3a\u5927\u7684\u529f\u80fd\u7c7b\uff0c\u8ba9\u5f00\u53d1\u53d8\u5f97\u66f4\u7b80\u5355\u9ad8\u6548\u3002\u9002\u7528\u4e8e\u73b0\u4ee3 Web \u5f00\u53d1\uff0c\u7279\u522b\u662f\u5728 React\u3001Vue\u3001Next.js\u3001Nuxt.js \u7b49\u6846\u67b6\u4e2d\u66f4\u53d7\u6b22\u8fce\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tailwind CSS framework Tailwind CSS \u6846\u67b6\u4ecb\u7ecd Tailwind CSS \u662f\u4e00\u4e2a\u529f\u80fd\u7c7b\uff08utility-first\uff09\u7684 CSS \u6846\u67b6\uff0c\u5b83\u63d0\u4f9b\u4e86\u5927\u91cf\u7684\u4f4e\u7ea7\u5b9e\u7528\u7c7b\uff0c\u8ba9\u5f00\u53d1\u8005\u53ef\u4ee5\u76f4\u63a5\u5728 HTML \u4ee3\u7801\u4e2d\u7f16\u5199\u6837\u5f0f\uff0c\u800c\u65e0\u9700\u521b\u5efa\u81ea\u5b9a\u4e49\u7684 CSS \u89c4\u5219\u3002\u5b83\u7684\u8bbe\u8ba1\u7406\u5ff5\u662f\u901a\u8fc7\u7ec4\u5408\u8fd9\u4e9b\u5c0f\u578b\u7684\u6837\u5f0f\u7c7b\u6765\u5feb\u901f\u6784\u5efa UI\uff0c\u800c\u4e0d\u662f\u50cf\u4f20\u7edf CSS \u90a3\u6837\u4f9d\u8d56\u9884\u5b9a\u4e49\u7684\u7ec4\u4ef6\u6216\u5168\u5c40\u6837\u5f0f\u3002 Tailwind CSS \u7684\u7279\u70b9 \u529f\u80fd\u7c7b\u4f18\u5148\uff1a\u4f7f\u7528\u539f\u5b50\u7c7b\uff08\u5982 p-4\u3001text-center\u3001bg-blue-500\uff09\u5feb\u901f\u6784\u5efa UI\u3002 \u9ad8\u5ea6\u53ef\u5b9a\u5236\uff1a\u53ef\u4ee5\u901a\u8fc7 tailwind.config.js \u8fdb\u884c\u914d\u7f6e\uff0c\u8c03\u6574\u989c\u8272\u3001\u5b57\u4f53\u3001\u95f4\u8ddd\u7b49\u3002 \u65e0\u9700\u989d\u5916 CSS \u6587\u4ef6\uff1a\u6240\u6709\u6837\u5f0f\u76f4\u63a5\u5728 HTML \u6587\u4ef6\u4e2d\u5b9a\u4e49\uff0c\u51cf\u5c11\u4e86 CSS \u4ee3\u7801\u91cf\u3002 \u54cd\u5e94\u5f0f\u8bbe\u8ba1\uff1a\u5185\u7f6e sm\u3001md\u3001lg\u3001xl \u7b49\u65ad\u70b9\u7c7b\uff0c\u65b9\u4fbf\u9002\u914d\u4e0d\u540c\u8bbe\u5907\u3002 Dark Mode \u652f\u6301\uff1a\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u6697\u9ed1\u6a21\u5f0f\u3002 \u5b89\u88c5 Tailwind CSS \u53ef\u4ee5\u901a\u8fc7 npm \u5b89\u88c5 Tailwind CSS\uff1a npm install -D tailwindcss postcss autoprefixer npx [&hellip;] <a class=\"read-more\" href=\"https:\/\/www.fanyamin.com\/wordpress\/?p=1971\" title=\"Permanent Link to: Tailwind CSS framework\">&rarr;Read&nbsp;more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1971","post","type-post","status-publish","format-standard","hentry","category-5"],"_links":{"self":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1971"}],"collection":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1971"}],"version-history":[{"count":1,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1971\/revisions"}],"predecessor-version":[{"id":1972,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1971\/revisions\/1972"}],"wp:attachment":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1971"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1971"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1971"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}