\/* Define CSS variables (custom properties) in the :root selector *\/\n :root {\n --primary-color: #3498db; \/* Main theme color *\/\n --secondary-color: #2ecc71; \/* Accent color *\/\n --text-color: #333; \/* Default text color *\/\n --font-size: 16px; \/* Base font size *\/\n --padding: 10px; \/* Base padding *\/\n }\n\n \/* General styles using variables *\/\n body {\n font-family: Arial, sans-serif;\n font-size: var(--font-size);\n color: var(--text-color);\n margin: 0;\n padding: 0;\n background-color: #f9f9f9;\n }\n\n header {\n background-color: var(--primary-color);\n color: white;\n text-align: center;\n padding: var(--padding);\n }\n\n .card {\n background-color: white;\n border: 1px solid #ddd;\n border-radius: 5px;\n margin: 20px;\n padding: var(--padding);\n box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);\n }\n\n .card h2 {\n color: var(--primary-color);\n }\n\n .card p {\n color: var(--text-color);\n }\n\n button {\n background-color: var(--secondary-color);\n color: white;\n border: none;\n border-radius: 5px;\n padding: calc(var(--padding) \/ 2) calc(var(--padding) * 2);\n cursor: pointer;\n font-size: var(--font-size);\n }\n\n button:hover {\n background-color: var(--primary-color);\n }\n\n \/* Dark mode example by overriding variables *\/\n body.dark-mode {\n --primary-color: #1abc9c;\n --secondary-color: #e74c3c;\n --text-color: #f9f9f9;\n background-color: #333;\n }\n<\/pre>\n\n\n\n\n \n \n 參考:\n<\/h3>\n\n<\/pre>\n
\n
- \nMDN Web 文件 - 使用 CSS 自訂屬性(變數(shù)) - 全面、適合初學(xué)者的解釋,包含定義、使用和更新 CSS 變數(shù)的範(fàn)例。 <\/li>\n
- \nW3Schools - CSS 變數(shù) - 透過即時程式碼範(fàn)例涵蓋 CSS 變數(shù)的基礎(chǔ)知識,以便快速練習(xí)。 <\/li>\n
- \nCSS 技巧 - 自訂屬性完整指南 - 綜合指南,包含真實用例和進階變數(shù)使用技巧。 <\/li>\n
- \nFreecodecamp - CSS 變數(shù)完整手冊 - 探索強大的技術(shù),例如級聯(lián)效果、基於媒體查詢的變數(shù)和範(fàn)圍管理。 <\/li>\n<\/ul>\n\n\n
\n\n\n \n \n 動畫和過渡\n<\/h2>\n\n
為您的網(wǎng)站添加動感可創(chuàng)造引人入勝的使用者體驗。 CSS 提供了兩種主要的動畫製作方式:<\/p>\n\n
\n \n \n 過渡\n<\/h3>\n\n
非常適合簡單的狀態(tài)變更:
\n<\/p>\n\/* Mobile-first approach *\/\n.container {\n width: 100%;\n padding: 10px;\n}\n\n\/* Tablet and larger *\/\n@media screen and (min-width: 768px) {\n .container {\n width: 750px;\n padding: 20px;\n }\n}\n\n\/* Desktop *\/\n@media screen and (min-width: 1024px) {\n .container {\n width: 960px;\n }\n}\n<\/pre>\n\n\n\n\n \n \n 關(guān)鍵影格動畫\n<\/h3>\n\n
對於更複雜的多步驟動畫:
\n<\/p>\n\n\n\n\n\n CSS:
\n<\/p>\n\n\/* Mobile First Approach *\/\n.services {\n padding: 20px;\n max-width: 1200px;\n margin: 0 auto;\n}\n\nh2 {\n text-align: center;\n color: #333;\n margin-bottom: 30px;\n}\n\n.services-container {\n display: flex;\n flex-direction: column;\n gap: 20px;\n}\n\n.service-card {\n padding: 20px;\n background: white;\n border-radius: 8px;\n box-shadow: 0 2px 4px rgba(0,0,0,0.1);\n}\n\nbutton {\n width: 100%;\n padding: 10px;\n background: #007bff;\n color: white;\n border: none;\n border-radius: 4px;\n cursor: pointer;\n}\n\n\/* Tablet *\/\n@media (min-width: 768px) {\n .services-container {\n flex-direction: row;\n flex-wrap: wrap;\n }\n\n .service-card {\n flex: 0 1 calc(50% - 20px);\n }\n}\n\n\/* Desktop *\/\n@media (min-width: 1024px) {\n .service-card {\n flex: 1;\n }\n\n button {\n width: auto;\n padding: 10px 20px;\n }\n}\n<\/pre>\n\n\n\n\n \n \n 先進的動畫技術(shù)\n<\/h3>\n\n
動畫中的 CSS 自訂屬性:
\n<\/p>\n\n\/* Base styles - Mobile First (320px and up) *\/\n.services {\n padding: 15px;\n max-width: 1200px;\n margin: 0 auto;\n overflow-x: hidden; \/* Prevent horizontal scroll *\/\n}\n\nh2 {\n text-align: center;\n color: #333;\n margin-bottom: 20px;\n font-size: clamp(1.5rem, 5vw, 2.5rem); \/* Fluid typography *\/\n}\n\n.services-container {\n display: flex;\n flex-direction: column;\n gap: 15px;\n}\n\n.service-card {\n padding: 15px;\n background: white;\n border-radius: 8px;\n box-shadow: 0 2px 4px rgba(0,0,0,0.1);\n transition: all 0.3s ease; \/* Smooth transitions for responsive changes *\/\n}\n\nbutton {\n width: 100%;\n padding: 8px;\n background: #007bff;\n color: white;\n border: none;\n border-radius: 4px;\n cursor: pointer;\n font-size: 14px;\n}\n\n\/* Small phones (375px and up) *\/\n@media (min-width: 375px) {\n .services {\n padding: 20px;\n }\n\n .service-card {\n padding: 20px;\n }\n}\n\n\/* Large phones (480px and up) *\/\n@media (min-width: 480px) {\n .services-container {\n gap: 20px;\n }\n\n button {\n padding: 10px;\n font-size: 16px;\n }\n}\n\n\/* Small tablets (600px and up) *\/\n@media (min-width: 600px) {\n .services-container {\n flex-direction: row;\n flex-wrap: wrap;\n }\n\n .service-card {\n flex: 0 1 calc(50% - 10px); \/* Two cards per row with gap consideration *\/\n }\n}\n\n\/* Tablets (768px and up) *\/\n@media (min-width: 768px) {\n .services {\n padding: 30px;\n }\n\n .service-card {\n padding: 25px; \/* Improved spacing for larger screens *\/\n }\n\n button: hover {\n \/* Add hover effect for non-touch devices *\/\n background: #0056b3;\n transform: translateY(-2px);\n }\n}\n\n\/* Small laptops (1024px and up) *\/\n@media (min-width: 1024px) {\n .service-card {\n flex: 1; \/* Three cards per row *\/\n transition: transform 0.3s ease, box-shadow 0.3s ease; \/* Add subtle hover effect *\/\n }\n\n .service-card:hover {\n transform: translateY(-5px);\n box-shadow: 0 4px 8px rgba(0,0,0,0.2);\n }\n\n button {\n \/* Change to inline button *\/\n width: auto;\n padding: 10px 20px;\n }\n}\n\n\/* Desktops (1200px and up) *\/\n@media (min-width: 1200px) {\n .services {\n padding: 40px;\n }\n\n .services-container {\n gap: 30px;\n }\n\n .service-card {\n padding: 30px;\n }\n}\n\n\/* Extra large screens (1440px and up) *\/\n@media (min-width: 1440px) {\n .services {\n max-width: 1400px; \/* Max width to maintain readability *\/\n }\n\n .service-card {\n padding: 35px; \/* Larger padding for extra large screens *\/\n }\n}\n\n\/* Print styles *\/\n@media print {\n .services {\n padding: 0;\n }\n\n .service-card {\n break-inside: avoid;\n box-shadow: none;\n border: 1px solid #ddd;\n }\n\n button {\n display: none;\n }\n}\n\n\/* Reduced motion preferences *\/\n@media (prefers-reduced-motion: reduce) {\n .service-card,\n button {\n transition: none;\n }\n}\n\n\/* Dark mode support *\/\n@media (prefers-color-scheme: dark) {\n .service-card {\n background: #2a2a2a;\n box-shadow: 0 2px 4px rgba(0,0,0,0.2);\n }\n\n h2 {\n color: #fff;\n }\n}\n<\/pre>\n\n\n\n\n \n \n 進階關(guān)鍵影格動畫:\n<\/h3>\n\n\n\n
:root {\n --primary-color: #007bff;\n --secondary-color: #6c757d;\n --spacing-unit: 1rem;\n}\n\n.button {\n background-color: var(--primary-color);\n padding: var(--spacing-unit);\n}\n<\/pre>\n\n\n\n\n \n \n 實踐練習(xí):互動卡\n<\/h2>\n\n
建立具有懸停效果的互動式卡片:<\/p>\n\n
HTML:
\n<\/p>\/* Mobile-first approach *\/\n.container {\n width: 100%;\n padding: 10px;\n}\n\n\/* Tablet and larger *\/\n@media screen and (min-width: 768px) {\n .container {\n width: 750px;\n padding: 20px;\n }\n}\n\n\/* Desktop *\/\n@media screen and (min-width: 1024px) {\n .container {\n width: 960px;\n }\n}\n<\/pre>\n\n\n\n\n \n \n 參考:\n<\/h3>\n\n<\/pre>\n
\n
- \nMDN Web 文件 - CSS 過渡 - 對 CSS 過渡的清晰介紹,解釋如何在更改樣式時創(chuàng)建平滑效果。 <\/li>\n
- \nMDN Web 文件 - CSS 動畫 - 關(guān)鍵影格、動畫屬性和創(chuàng)建複雜動畫的逐步指南。 <\/li>\n
- \nW3Schools - CSS 轉(zhuǎn)場 - 適合初學(xué)者使用即時程式碼編輯器以互動方式練習(xí)過渡和動畫。 <\/li>\n
- \nW3Schools - CSS 動畫 - 關(guān)於使用關(guān)鍵影格和轉(zhuǎn)場為網(wǎng)站添加動畫的簡單易懂的指南。 <\/li>\n
- \nCSS 技巧 - 動畫 - 討論響應(yīng)式動畫、減少可訪問性的運動以及媒體查詢整合。 <\/li>\n
- \nAnimate.css - 一個流行的 CSS 庫,提供預(yù)先建立的動畫,您可以輕鬆添加到您的專案中。 <\/li>\n<\/ul>\n\n\n
\n\n\n \n \n 最佳實踐和組織\n<\/h2>\n\n
\n \n \n CSS架構(gòu)\n<\/h3>\n\n
\n
- 使用一致的命名約定<\/li>\n
- 依組件\/功能組織 CSS 檔案<\/li>\n
- 盡可能保持較低的特異性<\/li>\n
- 有效註解你的程式碼\n<\/li>\n<\/ul>\n\n
\n\n\n\n CSS:
\n<\/p>\n\n\/* Mobile First Approach *\/\n.services {\n padding: 20px;\n max-width: 1200px;\n margin: 0 auto;\n}\n\nh2 {\n text-align: center;\n color: #333;\n margin-bottom: 30px;\n}\n\n.services-container {\n display: flex;\n flex-direction: column;\n gap: 20px;\n}\n\n.service-card {\n padding: 20px;\n background: white;\n border-radius: 8px;\n box-shadow: 0 2px 4px rgba(0,0,0,0.1);\n}\n\nbutton {\n width: 100%;\n padding: 10px;\n background: #007bff;\n color: white;\n border: none;\n border-radius: 4px;\n cursor: pointer;\n}\n\n\/* Tablet *\/\n@media (min-width: 768px) {\n .services-container {\n flex-direction: row;\n flex-wrap: wrap;\n }\n\n .service-card {\n flex: 0 1 calc(50% - 20px);\n }\n}\n\n\/* Desktop *\/\n@media (min-width: 1024px) {\n .service-card {\n flex: 1;\n }\n\n button {\n width: auto;\n padding: 10px 20px;\n }\n}\n<\/pre>\n\n\n\n\n \n \n 實踐練習(xí):CSS 架構(gòu)的最佳實踐\n<\/h2>\n\n\n\n
\n\n\n \n \nCSS 架構(gòu)練習(xí)<\/title>\n \n \n \n \n \n頭>\n\n \n\n\n\n \n \n \n 參考:\n<\/h3>\n\n<\/pre><\/pre>\n
\n
- \nBEM - 區(qū)塊元素修飾符 - 一種流行的命名 CSS 類別和建立樣式以提高可重複使用性和可維護性的方法。 <\/li>\n
- \nSMACSS - CSS 的可擴展和模組化架構(gòu) - 將 CSS 組織為邏輯和可維護類別的詳細(xì)框架。 <\/li>\n
- \nHarry Roberts 的 CSS 指南 - 使用邏輯檔案結(jié)構(gòu)和命名約定編寫可擴展、可維護的 CSS 的高品質(zhì)指南。 <\/li>\n<\/ul>\n\n\n
\n\n\n \n \n 建造時間到了! ?\n<\/h2>\n\n
現(xiàn)在輪到你將所學(xué)付諸實踐了!這是你的挑戰(zhàn):<\/p>\n
\n
- 建立新的 CodePen(在 codepen.io 上免費)<\/li>\n
- 建立我們介紹的範(fàn)例和練習(xí)<\/li>\n
- \n分享您的創(chuàng)作! <\/strong>在下面的評論中加入您的 CodePen 連結(jié)<\/li>\n<\/ul>\n\n
獎勵積分<\/strong>:在設(shè)計中加入自己的創(chuàng)意!我會親自審核並回覆評論中分享的每則 CodePen。 <\/p>\n\n
? 專業(yè)提示<\/strong>:請記得在 CSS 中加入註解來解釋您的想法。它可以幫助其他人從您的程式碼中學(xué)習(xí)! <\/p>\n\n\n
\n\n\n \n \n 接下來是什麼? ?\n<\/h2>\n\n
這是我們的 CSS 從零到英雄系列的第 2 部分。我們將在接下來的文章中更深入地探討更令人興奮的 CSS 概念。為了確保您不會錯過:<\/p>\n\n
\n
- ? 為這篇文章加書籤<\/strong>以便在編碼時快速參考<\/li>\n
- ?? 喜歡這篇文章<\/strong>如果您覺得它有幫助(它也可以幫助其他人找到它?。?\/li>\n
- ? 追蹤我<\/strong>觀看本系列的下一部分<\/li>\n<\/ol>\n\n
\n \n \n 讓我們聯(lián)絡(luò)吧! ?\n<\/h3>\n\n
你有嘗試過練習(xí)嗎?有疑問嗎?在評論中分享您的經(jīng)驗!我回覆每條評論並喜歡看到您的進步。 <\/p>\n\n
第三部分見!快樂編碼! ???????<\/p>\n\n\n \n\n \n \n\n \n "}
国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂
目錄
No. Section Link 1 Responsive Design Principles Link 2 CSS Variables and Custom Properties Link 3 Animations and Transitions Link 4 Best Practices and Organization Link
響應(yīng)式設(shè)計原則
在當(dāng)今的多設(shè)備世界中,響應(yīng)式設(shè)計不是可選的,而是必不可少的。無論是在智慧型手機還是大型桌面顯示器上查看,您的網(wǎng)站都應(yīng)該看起來很棒。
媒體查詢
媒體查詢是您的響應(yīng)式設(shè)計超能力:
/* Mobile-first approach */ .container { width: 100%; padding: 10px; } /* Tablet and larger */ @media screen and (min-width: 768px) { .container { width: 750px; padding: 20px; } } /* Desktop */ @media screen and (min-width: 1024px) { .container { width: 960px; } }響應(yīng)單位
使用相對單位使您的設(shè)計自然響應(yīng):
- rem:相對於根元素的字體大小
- em:相對於父元素的字體大小
- vw/vh:相對於視口尺寸
- %:相對於父元素的大小
實踐練習(xí):回應(yīng)服務(wù)部分
創(chuàng)建一個響應(yīng)式服務(wù)部分,使用媒體查詢和靈活的單元無縫適應(yīng)不同的螢?zāi)怀叽纭?
HTML:
<section> <p>CSS:<br> </p> <pre class="brush:php;toolbar:false">/* Mobile First Approach */ .services { padding: 20px; max-width: 1200px; margin: 0 auto; } h2 { text-align: center; color: #333; margin-bottom: 30px; } .services-container { display: flex; flex-direction: column; gap: 20px; } .service-card { padding: 20px; background: white; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); } button { width: 100%; padding: 10px; background: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; } /* Tablet */ @media (min-width: 768px) { .services-container { flex-direction: row; flex-wrap: wrap; } .service-card { flex: 0 1 calc(50% - 20px); } } /* Desktop */ @media (min-width: 1024px) { .service-card { flex: 1; } button { width: auto; padding: 10px 20px; } }CSS:讓我們來探索一下服務(wù)部分的更具體的斷點。
/* Base styles - Mobile First (320px and up) */ .services { padding: 15px; max-width: 1200px; margin: 0 auto; overflow-x: hidden; /* Prevent horizontal scroll */ } h2 { text-align: center; color: #333; margin-bottom: 20px; font-size: clamp(1.5rem, 5vw, 2.5rem); /* Fluid typography */ } .services-container { display: flex; flex-direction: column; gap: 15px; } .service-card { padding: 15px; background: white; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); transition: all 0.3s ease; /* Smooth transitions for responsive changes */ } button { width: 100%; padding: 8px; background: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 14px; } /* Small phones (375px and up) */ @media (min-width: 375px) { .services { padding: 20px; } .service-card { padding: 20px; } } /* Large phones (480px and up) */ @media (min-width: 480px) { .services-container { gap: 20px; } button { padding: 10px; font-size: 16px; } } /* Small tablets (600px and up) */ @media (min-width: 600px) { .services-container { flex-direction: row; flex-wrap: wrap; } .service-card { flex: 0 1 calc(50% - 10px); /* Two cards per row with gap consideration */ } } /* Tablets (768px and up) */ @media (min-width: 768px) { .services { padding: 30px; } .service-card { padding: 25px; /* Improved spacing for larger screens */ } button: hover { /* Add hover effect for non-touch devices */ background: #0056b3; transform: translateY(-2px); } } /* Small laptops (1024px and up) */ @media (min-width: 1024px) { .service-card { flex: 1; /* Three cards per row */ transition: transform 0.3s ease, box-shadow 0.3s ease; /* Add subtle hover effect */ } .service-card:hover { transform: translateY(-5px); box-shadow: 0 4px 8px rgba(0,0,0,0.2); } button { /* Change to inline button */ width: auto; padding: 10px 20px; } } /* Desktops (1200px and up) */ @media (min-width: 1200px) { .services { padding: 40px; } .services-container { gap: 30px; } .service-card { padding: 30px; } } /* Extra large screens (1440px and up) */ @media (min-width: 1440px) { .services { max-width: 1400px; /* Max width to maintain readability */ } .service-card { padding: 35px; /* Larger padding for extra large screens */ } } /* Print styles */ @media print { .services { padding: 0; } .service-card { break-inside: avoid; box-shadow: none; border: 1px solid #ddd; } button { display: none; } } /* Reduced motion preferences */ @media (prefers-reduced-motion: reduce) { .service-card, button { transition: none; } } /* Dark mode support */ @media (prefers-color-scheme: dark) { .service-card { background: #2a2a2a; box-shadow: 0 2px 4px rgba(0,0,0,0.2); } h2 { color: #fff; } }參考:
- MDN Web 文件 - 響應(yīng)式設(shè)計基礎(chǔ) - 響應(yīng)式設(shè)計概念的精彩介紹,涵蓋視窗、斷點和靈活佈局。
- FreeCodeCamp - 響應(yīng)式網(wǎng)頁設(shè)計認(rèn)證 - 涵蓋響應(yīng)式設(shè)計原則、網(wǎng)格、媒體查詢和可訪問性的完整課程。
- 我可以使用 - 檢查瀏覽器相容性以取得響應(yīng)式設(shè)計功能,例如媒體查詢和 Flexbox。
- 響應(yīng)式設(shè)計備忘單 - 以易於理解的格式涵蓋關(guān)鍵的響應(yīng)式設(shè)計屬性和技術(shù)。
CSS 變數(shù)和自訂屬性
CSS 變數(shù)(自訂屬性)為您的樣式表帶來類似程式設(shè)計的彈性。它們使維護更容易並實現(xiàn)動態(tài)造型。
:root { --primary-color: #007bff; --secondary-color: #6c757d; --spacing-unit: 1rem; } .button { background-color: var(--primary-color); padding: var(--spacing-unit); }實踐練習(xí):用於主題化和可重複使用性的 CSS 變量
<body> <header> <h1>CSS Variables & Custom Properties</h1> </header> <main> <section> <pre class="brush:php;toolbar:false">/* Define CSS variables (custom properties) in the :root selector */ :root { --primary-color: #3498db; /* Main theme color */ --secondary-color: #2ecc71; /* Accent color */ --text-color: #333; /* Default text color */ --font-size: 16px; /* Base font size */ --padding: 10px; /* Base padding */ } /* General styles using variables */ body { font-family: Arial, sans-serif; font-size: var(--font-size); color: var(--text-color); margin: 0; padding: 0; background-color: #f9f9f9; } header { background-color: var(--primary-color); color: white; text-align: center; padding: var(--padding); } .card { background-color: white; border: 1px solid #ddd; border-radius: 5px; margin: 20px; padding: var(--padding); box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); } .card h2 { color: var(--primary-color); } .card p { color: var(--text-color); } button { background-color: var(--secondary-color); color: white; border: none; border-radius: 5px; padding: calc(var(--padding) / 2) calc(var(--padding) * 2); cursor: pointer; font-size: var(--font-size); } button:hover { background-color: var(--primary-color); } /* Dark mode example by overriding variables */ body.dark-mode { --primary-color: #1abc9c; --secondary-color: #e74c3c; --text-color: #f9f9f9; background-color: #333; }參考:
- MDN Web 文件 - 使用 CSS 自訂屬性(變數(shù)) - 全面、適合初學(xué)者的解釋,包含定義、使用和更新 CSS 變數(shù)的範(fàn)例。
- W3Schools - CSS 變數(shù) - 透過即時程式碼範(fàn)例涵蓋 CSS 變數(shù)的基礎(chǔ)知識,以便快速練習(xí)。
- CSS 技巧 - 自訂屬性完整指南 - 綜合指南,包含真實用例和進階變數(shù)使用技巧。
- Freecodecamp - CSS 變數(shù)完整手冊 - 探索強大的技術(shù),例如級聯(lián)效果、基於媒體查詢的變數(shù)和範(fàn)圍管理。
動畫和過渡
為您的網(wǎng)站添加動感可創(chuàng)造引人入勝的使用者體驗。 CSS 提供了兩種主要的動畫製作方式:
過渡
非常適合簡單的狀態(tài)變更:
/* Mobile-first approach */ .container { width: 100%; padding: 10px; } /* Tablet and larger */ @media screen and (min-width: 768px) { .container { width: 750px; padding: 20px; } } /* Desktop */ @media screen and (min-width: 1024px) { .container { width: 960px; } }關(guān)鍵影格動畫
對於更複雜的多步驟動畫:
<section> <p>CSS:<br> </p> <pre class="brush:php;toolbar:false">/* Mobile First Approach */ .services { padding: 20px; max-width: 1200px; margin: 0 auto; } h2 { text-align: center; color: #333; margin-bottom: 30px; } .services-container { display: flex; flex-direction: column; gap: 20px; } .service-card { padding: 20px; background: white; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); } button { width: 100%; padding: 10px; background: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; } /* Tablet */ @media (min-width: 768px) { .services-container { flex-direction: row; flex-wrap: wrap; } .service-card { flex: 0 1 calc(50% - 20px); } } /* Desktop */ @media (min-width: 1024px) { .service-card { flex: 1; } button { width: auto; padding: 10px 20px; } }先進的動畫技術(shù)
動畫中的 CSS 自訂屬性:
/* Base styles - Mobile First (320px and up) */ .services { padding: 15px; max-width: 1200px; margin: 0 auto; overflow-x: hidden; /* Prevent horizontal scroll */ } h2 { text-align: center; color: #333; margin-bottom: 20px; font-size: clamp(1.5rem, 5vw, 2.5rem); /* Fluid typography */ } .services-container { display: flex; flex-direction: column; gap: 15px; } .service-card { padding: 15px; background: white; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); transition: all 0.3s ease; /* Smooth transitions for responsive changes */ } button { width: 100%; padding: 8px; background: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 14px; } /* Small phones (375px and up) */ @media (min-width: 375px) { .services { padding: 20px; } .service-card { padding: 20px; } } /* Large phones (480px and up) */ @media (min-width: 480px) { .services-container { gap: 20px; } button { padding: 10px; font-size: 16px; } } /* Small tablets (600px and up) */ @media (min-width: 600px) { .services-container { flex-direction: row; flex-wrap: wrap; } .service-card { flex: 0 1 calc(50% - 10px); /* Two cards per row with gap consideration */ } } /* Tablets (768px and up) */ @media (min-width: 768px) { .services { padding: 30px; } .service-card { padding: 25px; /* Improved spacing for larger screens */ } button: hover { /* Add hover effect for non-touch devices */ background: #0056b3; transform: translateY(-2px); } } /* Small laptops (1024px and up) */ @media (min-width: 1024px) { .service-card { flex: 1; /* Three cards per row */ transition: transform 0.3s ease, box-shadow 0.3s ease; /* Add subtle hover effect */ } .service-card:hover { transform: translateY(-5px); box-shadow: 0 4px 8px rgba(0,0,0,0.2); } button { /* Change to inline button */ width: auto; padding: 10px 20px; } } /* Desktops (1200px and up) */ @media (min-width: 1200px) { .services { padding: 40px; } .services-container { gap: 30px; } .service-card { padding: 30px; } } /* Extra large screens (1440px and up) */ @media (min-width: 1440px) { .services { max-width: 1400px; /* Max width to maintain readability */ } .service-card { padding: 35px; /* Larger padding for extra large screens */ } } /* Print styles */ @media print { .services { padding: 0; } .service-card { break-inside: avoid; box-shadow: none; border: 1px solid #ddd; } button { display: none; } } /* Reduced motion preferences */ @media (prefers-reduced-motion: reduce) { .service-card, button { transition: none; } } /* Dark mode support */ @media (prefers-color-scheme: dark) { .service-card { background: #2a2a2a; box-shadow: 0 2px 4px rgba(0,0,0,0.2); } h2 { color: #fff; } }進階關(guān)鍵影格動畫:
:root { --primary-color: #007bff; --secondary-color: #6c757d; --spacing-unit: 1rem; } .button { background-color: var(--primary-color); padding: var(--spacing-unit); }實踐練習(xí):互動卡
建立具有懸停效果的互動式卡片:
HTML:
/* Mobile-first approach */ .container { width: 100%; padding: 10px; } /* Tablet and larger */ @media screen and (min-width: 768px) { .container { width: 750px; padding: 20px; } } /* Desktop */ @media screen and (min-width: 1024px) { .container { width: 960px; } }參考:
- MDN Web 文件 - CSS 過渡 - 對 CSS 過渡的清晰介紹,解釋如何在更改樣式時創(chuàng)建平滑效果。
- MDN Web 文件 - CSS 動畫 - 關(guān)鍵影格、動畫屬性和創(chuàng)建複雜動畫的逐步指南。
- W3Schools - CSS 轉(zhuǎn)場 - 適合初學(xué)者使用即時程式碼編輯器以互動方式練習(xí)過渡和動畫。
- W3Schools - CSS 動畫 - 關(guān)於使用關(guān)鍵影格和轉(zhuǎn)場為網(wǎng)站添加動畫的簡單易懂的指南。
- CSS 技巧 - 動畫 - 討論響應(yīng)式動畫、減少可訪問性的運動以及媒體查詢整合。
- Animate.css - 一個流行的 CSS 庫,提供預(yù)先建立的動畫,您可以輕鬆添加到您的專案中。
最佳實踐和組織
CSS架構(gòu)
- 使用一致的命名約定
- 依組件/功能組織 CSS 檔案
- 盡可能保持較低的特異性
- 有效註解你的程式碼
<section> <p>CSS:<br> </p> <pre class="brush:php;toolbar:false">/* Mobile First Approach */ .services { padding: 20px; max-width: 1200px; margin: 0 auto; } h2 { text-align: center; color: #333; margin-bottom: 30px; } .services-container { display: flex; flex-direction: column; gap: 20px; } .service-card { padding: 20px; background: white; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); } button { width: 100%; padding: 10px; background: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; } /* Tablet */ @media (min-width: 768px) { .services-container { flex-direction: row; flex-wrap: wrap; } .service-card { flex: 0 1 calc(50% - 20px); } } /* Desktop */ @media (min-width: 1024px) { .service-card { flex: 1; } button { width: auto; padding: 10px 20px; } }實踐練習(xí):CSS 架構(gòu)的最佳實踐
<title>CSS 架構(gòu)練習(xí)</title> <link rel="stylesheet" href="styles/reset.css"> <!-- 重設(shè)預(yù)設(shè)瀏覽器樣式 --> <link rel="stylesheet" href="styles/layout.css"> <!-- 佈局相關(guān)的樣式 --> <!-- 標(biāo)題元件樣式 --> <link rel="stylesheet" href="styles/components/card.css"> <!-- 卡片組件樣式 --> <link rel="stylesheet" href="styles/utilities.css"> <!-- 用於快速修復(fù)的實用程式類別 --> 頭> <h3> 參考: </h3>
- BEM - 區(qū)塊元素修飾符 - 一種流行的命名 CSS 類別和建立樣式以提高可重複使用性和可維護性的方法。
- SMACSS - CSS 的可擴展和模組化架構(gòu) - 將 CSS 組織為邏輯和可維護類別的詳細(xì)框架。
- Harry Roberts 的 CSS 指南 - 使用邏輯檔案結(jié)構(gòu)和命名約定編寫可擴展、可維護的 CSS 的高品質(zhì)指南。
建造時間到了! ?
現(xiàn)在輪到你將所學(xué)付諸實踐了!這是你的挑戰(zhàn):
- 建立新的 CodePen(在 codepen.io 上免費)
- 建立我們介紹的範(fàn)例和練習(xí)
- 分享您的創(chuàng)作! 在下面的評論中加入您的 CodePen 連結(jié)
獎勵積分:在設(shè)計中加入自己的創(chuàng)意!我會親自審核並回覆評論中分享的每則 CodePen。
? 專業(yè)提示:請記得在 CSS 中加入註解來解釋您的想法。它可以幫助其他人從您的程式碼中學(xué)習(xí)!
接下來是什麼? ?
這是我們的 CSS 從零到英雄系列的第 2 部分。我們將在接下來的文章中更深入地探討更令人興奮的 CSS 概念。為了確保您不會錯過:
- ? 為這篇文章加書籤以便在編碼時快速參考
- ?? 喜歡這篇文章如果您覺得它有幫助(它也可以幫助其他人找到它!)
- ? 追蹤我觀看本系列的下一部分
讓我們聯(lián)絡(luò)吧! ?
你有嘗試過練習(xí)嗎?有疑問嗎?在評論中分享您的經(jīng)驗!我回覆每條評論並喜歡看到您的進步。
第三部分見!快樂編碼! ???????
以上是《給所有人的權(quán)威 CSS 指南》中的掌握 CSS |第2部分的詳細(xì)內(nèi)容。更多資訊請關(guān)注PHP中文網(wǎng)其他相關(guān)文章!
本網(wǎng)站聲明本文內(nèi)容由網(wǎng)友自願投稿,版權(quán)歸原作者所有。本站不承擔(dān)相應(yīng)的法律責(zé)任。如發(fā)現(xiàn)涉嫌抄襲或侵權(quán)的內(nèi)容,請聯(lián)絡(luò)admin@php.cn![]()
熱AI工具
![]()
Undress AI Tool
免費脫衣圖片
![]()
Undresser.AI Undress
人工智慧驅(qū)動的應(yīng)用程序,用於創(chuàng)建逼真的裸體照片
![]()
AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。
![]()
Clothoff.io
AI脫衣器
![]()
Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!
![]()
熱門文章
Agnes Tachyon Build Guide |漂亮的德比志2 週前 By Jack chenOguri Cap Build Guide |漂亮的德比志2 週前 By Jack chen約會一切:德克和哈珀關(guān)係指南1 個月前 By Jack chen沙丘:覺醒 - 高級行星學(xué)家Quest演練1 個月前 By Jack chenPalia:Rasquellywag的Riches Quest演練4 週前 By DDD![]()
熱工具
![]()
記事本++7.3.1
好用且免費的程式碼編輯器
![]()
SublimeText3漢化版
中文版,非常好用
![]()
禪工作室 13.0.1
強大的PHP整合開發(fā)環(huán)境
![]()
Dreamweaver CS6
視覺化網(wǎng)頁開發(fā)工具
![]()
SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)
![]()
熱門話題
See all articles什麼是'渲染障礙CSS”? Jun 24, 2025 am 12:42 AM
CSS會阻塞頁面渲染是因為瀏覽器默認(rèn)將內(nèi)聯(lián)和外部CSS視為關(guān)鍵資源,尤其是使用引入的樣式表、頭部大量內(nèi)聯(lián)CSS以及未優(yōu)化的媒體查詢樣式。 1.提取關(guān)鍵CSS並內(nèi)嵌至HTML;2.延遲加載非關(guān)鍵CSS通過JavaScript;3.使用media屬性優(yōu)化加載如打印樣式;4.壓縮合併CSS減少請求。建議使用工具提取關(guān)鍵CSS,結(jié)合rel="preload"異步加載,合理使用media延遲加載,避免過度拆分與復(fù)雜腳本控制。
外部與內(nèi)部CSS:最好的方法是什麼? Jun 20, 2025 am 12:45 AM
thebestapphachforcssdepprodsontheproject'sspefificneeds.forlargerprojects,externalcsSissBetterDuoSmaintoMaintainability andReusability; forsMallerProjectsorsingle-pageApplications,InternaltCsmightBemoresobleable.InternalCsmightBemorese.it.it'sclucialtobalancepopryseceneceenceprodrenceprodrenceNeed
我的CSS必須在較低的情況下嗎? Jun 19, 2025 am 12:29 AM
否,CSSDOESNOTHAVETOBEINLOWERCASE.CHOMENDENS,使用flowercaseisrecommondendendending:1)一致性和可讀性,2)避免使用促進性技術(shù),3)潛在的Performent FormanceBenefits,以及4)RightCollaboraboraboraboraboraboraboraboraboraboraboraboraboraboraboraboraborationWithInteams。
CSS案例靈敏度:了解重要的 Jun 20, 2025 am 12:09 AM
cssismostlycaseminemintiment,buturlsandfontfamilynamesarecase敏感。 1)屬性和valueslikeColor:紅色; prenotcase-sensive.2)urlsmustmustmatchtheserver'server'scase,例如
什麼是AutoPrefixer,它如何工作? Jul 02, 2025 am 01:15 AM
Autoprefixer是一個根據(jù)目標(biāo)瀏覽器範(fàn)圍自動為CSS屬性添加廠商前綴的工具。 1.它解決了手動維護前綴易出錯的問題;2.通過PostCSS插件形式工作,解析CSS、分析需加前綴的屬性、依配置生成代碼;3.使用步驟包括安裝插件、設(shè)置browserslist、在構(gòu)建流程中啟用;4.注意事項有不手動加前綴、保持配置更新、非所有屬性都加前綴、建議配合預(yù)處理器使用。
什麼是CSS計數(shù)器? Jun 19, 2025 am 12:34 AM
csscounterscanautomationallymentermentermentections和lists.1)usecounter-ensettoInitializize,反插入式發(fā)芽,andcounter()orcounters()
CSS:何時重要(何時不)? Jun 19, 2025 am 12:27 AM
在CSS中,選擇器和屬性名不區(qū)分大小寫,而值、命名顏色、URL和自定義屬性則區(qū)分大小寫。 1.選擇器和屬性名不區(qū)分大小寫,例如background-color和Background-Color相同。 2.值中的十六進制顏色不區(qū)分大小寫,但命名顏色區(qū)分大小寫,如red有效而Red無效。 3.URL區(qū)分大小寫,可能導(dǎo)致文件加載問題。 4.自定義屬性(變量)區(qū)分大小寫,使用時需注意大小寫一致。
什麼是圓錐級函數(shù)? Jul 01, 2025 am 01:16 AM
theconic-Gradient()functionIncsscreatesCircularGradientsThatRotateColorStopSaroundAcentralPoint.1.IsidealForPieCharts,ProgressIndicators,colordichers,colorwheels和decorativeBackgrounds.2.itworksbysbysbysbydefindefingincolordefingincolorstopsatspecificains off.
![]()