\/* 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
\n
- \nMDN Web 文檔 - 使用 CSS 自定義屬性(變量) - 全面、適合初學(xué)者的解釋,包含有關(guān)定義、使用和更新 CSS 變量的示例。<\/li>\n
- \nW3Schools - CSS 變量 - 通過(guò)實(shí)時(shí)代碼示例涵蓋 CSS 變量的基礎(chǔ)知識(shí),以便快速練習(xí)。<\/li>\n
- \nCSS 技巧 - 自定義屬性完整指南 - 綜合指南,包含真實(shí)用例和高級(jí)變量使用技巧。<\/li>\n
- \nFreecodecamp - CSS 變量完整手冊(cè) - 探索強(qiáng)大的技術(shù),例如級(jí)聯(lián)效果、基于媒體查詢的變量和范圍管理。<\/li>\n<\/ul>\n\n\n
\n\n\n \n \n 動(dòng)畫和過(guò)渡 \n<\/h2>\n\n
為您的網(wǎng)站添加動(dòng)感可創(chuàng)造引人入勝的用戶體驗(yàn)。 CSS 提供了兩種主要的動(dòng)畫制作方式:<\/p>\n\n
\n \n \n 過(guò)渡\n<\/h3>\n\n
非常適合簡(jiǎn)單的狀態(tài)更改:
\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 關(guān)鍵幀動(dòng)畫\n<\/h3>\n\n
對(duì)于更復(fù)雜的多步驟動(dòng)畫:
\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 先進(jìn)的動(dòng)畫技術(shù)\n<\/h3>\n\n
動(dòng)畫中的 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 高級(jí)關(guān)鍵幀動(dòng)畫:\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 實(shí)踐練習(xí):互動(dòng)卡\n<\/h2>\n\n
創(chuàng)建具有懸停效果的交互式卡片:<\/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
\n
- \nMDN Web 文檔 - CSS 過(guò)渡 - 對(duì) CSS 過(guò)渡的清晰介紹,解釋如何在更改樣式時(shí)創(chuàng)建平滑效果。<\/li>\n
- \nMDN Web 文檔 - CSS 動(dòng)畫 - 關(guān)鍵幀、動(dòng)畫屬性和創(chuàng)建復(fù)雜動(dòng)畫的分步指南。<\/li>\n
- \nW3Schools - CSS 過(guò)渡 - 適合初學(xué)者使用實(shí)時(shí)代碼編輯器以交互方式練習(xí)過(guò)渡和動(dòng)畫。<\/li>\n
- \nW3Schools - CSS 動(dòng)畫 - 關(guān)于使用關(guān)鍵幀和過(guò)渡向網(wǎng)站添加動(dòng)畫的簡(jiǎn)單易懂的指南。<\/li>\n
- \nCSS 技巧 - 動(dòng)畫 - 討論響應(yīng)式動(dòng)畫、減少可訪問(wèn)性的運(yùn)動(dòng)以及媒體查詢集成。<\/li>\n
- \nAnimate.css - 一個(gè)流行的 CSS 庫(kù),提供預(yù)構(gòu)建的動(dòng)畫,您可以輕松添加到您的項(xiàng)目中。<\/li>\n<\/ul>\n\n\n
\n\n\n \n \n 最佳實(shí)踐和組織 \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 實(shí)踐練習(xí):CSS 架構(gòu)的最佳實(shí)踐\n<\/h2>\n\n\n\n
<!DOCTYPE html>\n\n<頭>\n \n \nCSS 架構(gòu)練習(xí)<\/title>\n \n \n <鏈接 rel=\"stylesheet\" href=\"styles\/components\/header.css\"> \n \n \n<\/頭>\n\n \n\n\n\n \n \n \n 參考:\n<\/h3>\n\n<\/pre>\n
\n
- \nBEM - 塊元素修飾符 - 一種流行的命名 CSS 類和構(gòu)建樣式以提高可重用性和可維護(hù)性的方法。<\/li>\n
- \nSMACSS - CSS 的可擴(kuò)展和模塊化架構(gòu) - 將 CSS 組織為邏輯和可維護(hù)類別的詳細(xì)框架。<\/li>\n
- \nHarry Roberts 的 CSS 指南 - 使用邏輯文件結(jié)構(gòu)和命名約定編寫可擴(kuò)展、可維護(hù)的 CSS 的高質(zhì)量指南。<\/li>\n<\/ul>\n\n\n
\n\n\n \n \n 建造時(shí)間到了! ?\n<\/h2>\n\n
現(xiàn)在輪到你將所學(xué)付諸實(shí)踐了!這是你的挑戰(zhàn):<\/p>\n
\n
- 創(chuàng)建新的 CodePen(在 codepen.io 上免費(fèi))<\/li>\n
- 構(gòu)建我們介紹的示例和練習(xí)<\/li>\n
- \n分享您的創(chuàng)作!<\/strong>在下面的評(píng)論中添加您的 CodePen 鏈接<\/li>\n<\/ul>\n\n
獎(jiǎng)勵(lì)積分<\/strong>:在設(shè)計(jì)中添加您自己的創(chuàng)意!我會(huì)親自審核并回復(fù)評(píng)論中分享的每條 CodePen。<\/p>\n\n
? 專業(yè)提示<\/strong>:請(qǐng)記住在 CSS 中添加注釋來(lái)解釋您的想法。它可以幫助其他人從您的代碼中學(xué)習(xí)!<\/p>\n\n\n
\n\n\n \n \n 接下來(lái)是什么? ?\n<\/h2>\n\n
這是我們的 CSS 從零到英雄系列的第 2 部分。我們將在接下來(lái)的文章中更深入地探討更令人興奮的 CSS 概念。為了確保您不會(huì)錯(cuò)過(guò):<\/p>\n\n
\n
- ? 為這篇文章添加書簽<\/strong>以便在編碼時(shí)快速參考<\/li>\n
- ?? 喜歡這篇文章<\/strong>如果您覺得它有幫助(它也可以幫助其他人找到它?。?\/li>\n
- ? 關(guān)注我<\/strong>觀看本系列的下一部分<\/li>\n<\/ol>\n\n
\n \n \n 讓我們聯(lián)系吧! ?\n<\/h3>\n\n
你嘗試過(guò)練習(xí)嗎?有疑問(wèn)嗎?在評(píng)論中分享您的經(jīng)驗(yàn)!我回復(fù)每條評(píng)論并喜歡看到您的進(jìn)步。<\/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è)計(jì)原則
在當(dāng)今的多設(shè)備世界中,響應(yīng)式設(shè)計(jì)不是可選的,而是必不可少的。無(wú)論是在智能手機(jī)還是大型桌面顯示器上查看,您的網(wǎng)站都應(yīng)該看起來(lái)很棒。
媒體查詢
媒體查詢是您的響應(yīng)式設(shè)計(jì)超能力:
/* 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)單位
使用相對(duì)單位使您的設(shè)計(jì)自然響應(yīng):
- rem:相對(duì)于根元素的字體大小
- em:相對(duì)于父元素的字體大小
- vw/vh:相對(duì)于視口尺寸
- %:相對(duì)于父元素的大小
實(shí)踐練習(xí):響應(yīng)服務(wù)部分
創(chuàng)建一個(gè)響應(yīng)式服務(wù)部分,使用媒體查詢和靈活的單元無(wú)縫適應(yīng)不同的屏幕尺寸。
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ù)部分的更具體的斷點(diǎn)。
/* 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è)計(jì)基礎(chǔ) - 響應(yīng)式設(shè)計(jì)概念的精彩介紹,涵蓋視口、斷點(diǎn)和靈活布局。
- FreeCodeCamp - 響應(yīng)式網(wǎng)頁(yè)設(shè)計(jì)認(rèn)證 - 涵蓋響應(yīng)式設(shè)計(jì)原理、網(wǎng)格、媒體查詢和可訪問(wèn)性的完整課程。
- 我可以使用 - 檢查瀏覽器兼容性以獲取響應(yīng)式設(shè)計(jì)功能,例如媒體查詢和 Flexbox。
- 響應(yīng)式設(shè)計(jì)備忘單 - 以易于理解的格式涵蓋關(guān)鍵的響應(yīng)式設(shè)計(jì)屬性和技術(shù)。
CSS 變量和自定義屬性
CSS 變量(自定義屬性)為您的樣式表帶來(lái)類似編程的靈活性。它們使維護(hù)更容易并實(shí)現(xiàn)動(dòng)態(tài)造型。
:root { --primary-color: #007bff; --secondary-color: #6c757d; --spacing-unit: 1rem; } .button { background-color: var(--primary-color); padding: var(--spacing-unit); }實(shí)踐練習(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 自定義屬性(變量) - 全面、適合初學(xué)者的解釋,包含有關(guān)定義、使用和更新 CSS 變量的示例。
- W3Schools - CSS 變量 - 通過(guò)實(shí)時(shí)代碼示例涵蓋 CSS 變量的基礎(chǔ)知識(shí),以便快速練習(xí)。
- CSS 技巧 - 自定義屬性完整指南 - 綜合指南,包含真實(shí)用例和高級(jí)變量使用技巧。
- Freecodecamp - CSS 變量完整手冊(cè) - 探索強(qiáng)大的技術(shù),例如級(jí)聯(lián)效果、基于媒體查詢的變量和范圍管理。
動(dòng)畫和過(guò)渡
為您的網(wǎng)站添加動(dòng)感可創(chuàng)造引人入勝的用戶體驗(yàn)。 CSS 提供了兩種主要的動(dòng)畫制作方式:
過(guò)渡
非常適合簡(jiǎn)單的狀態(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)鍵幀動(dòng)畫
對(duì)于更復(fù)雜的多步驟動(dòng)畫:
<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; } }先進(jìn)的動(dòng)畫技術(shù)
動(dòng)畫中的 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; } }高級(jí)關(guān)鍵幀動(dòng)畫:
:root { --primary-color: #007bff; --secondary-color: #6c757d; --spacing-unit: 1rem; } .button { background-color: var(--primary-color); padding: var(--spacing-unit); }實(shí)踐練習(xí):互動(dòng)卡
創(chuàng)建具有懸停效果的交互式卡片:
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 過(guò)渡 - 對(duì) CSS 過(guò)渡的清晰介紹,解釋如何在更改樣式時(shí)創(chuàng)建平滑效果。
- MDN Web 文檔 - CSS 動(dòng)畫 - 關(guān)鍵幀、動(dòng)畫屬性和創(chuàng)建復(fù)雜動(dòng)畫的分步指南。
- W3Schools - CSS 過(guò)渡 - 適合初學(xué)者使用實(shí)時(shí)代碼編輯器以交互方式練習(xí)過(guò)渡和動(dòng)畫。
- W3Schools - CSS 動(dòng)畫 - 關(guān)于使用關(guān)鍵幀和過(guò)渡向網(wǎng)站添加動(dòng)畫的簡(jiǎn)單易懂的指南。
- CSS 技巧 - 動(dòng)畫 - 討論響應(yīng)式動(dòng)畫、減少可訪問(wèn)性的運(yùn)動(dòng)以及媒體查詢集成。
- Animate.css - 一個(gè)流行的 CSS 庫(kù),提供預(yù)構(gòu)建的動(dòng)畫,您可以輕松添加到您的項(xiàng)目中。
最佳實(shí)踐和組織
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; } }實(shí)踐練習(xí):CSS 架構(gòu)的最佳實(shí)踐
<!DOCTYPE html> <html lang="zh-cn"> <頭> <title>CSS 架構(gòu)練習(xí)</title> <link rel="stylesheet" href="styles/reset.css"> <!-- 重置默認(rèn)瀏覽器樣式 --> <link rel="stylesheet" href="styles/layout.css"> <鏈接 rel="stylesheet" href="styles/components/header.css"> <!-- 標(biāo)題組件樣式 --> <link rel="stylesheet" href="styles/components/card.css"> <!-- 卡片組件樣式 --> <link rel="stylesheet" href="styles/utilities.css"> <!-- 用于快速修復(fù)的實(shí)用程序類 --> </頭> <h3> 參考: </h3>
- BEM - 塊元素修飾符 - 一種流行的命名 CSS 類和構(gòu)建樣式以提高可重用性和可維護(hù)性的方法。
- SMACSS - CSS 的可擴(kuò)展和模塊化架構(gòu) - 將 CSS 組織為邏輯和可維護(hù)類別的詳細(xì)框架。
- Harry Roberts 的 CSS 指南 - 使用邏輯文件結(jié)構(gòu)和命名約定編寫可擴(kuò)展、可維護(hù)的 CSS 的高質(zhì)量指南。
建造時(shí)間到了! ?
現(xiàn)在輪到你將所學(xué)付諸實(shí)踐了!這是你的挑戰(zhàn):
- 創(chuàng)建新的 CodePen(在 codepen.io 上免費(fèi))
- 構(gòu)建我們介紹的示例和練習(xí)
- 分享您的創(chuàng)作!在下面的評(píng)論中添加您的 CodePen 鏈接
獎(jiǎng)勵(lì)積分:在設(shè)計(jì)中添加您自己的創(chuàng)意!我會(huì)親自審核并回復(fù)評(píng)論中分享的每條 CodePen。
? 專業(yè)提示:請(qǐng)記住在 CSS 中添加注釋來(lái)解釋您的想法。它可以幫助其他人從您的代碼中學(xué)習(xí)!
接下來(lái)是什么? ?
這是我們的 CSS 從零到英雄系列的第 2 部分。我們將在接下來(lái)的文章中更深入地探討更令人興奮的 CSS 概念。為了確保您不會(huì)錯(cuò)過(guò):
- ? 為這篇文章添加書簽以便在編碼時(shí)快速參考
- ?? 喜歡這篇文章如果您覺得它有幫助(它也可以幫助其他人找到它!)
- ? 關(guān)注我觀看本系列的下一部分
讓我們聯(lián)系吧! ?
你嘗試過(guò)練習(xí)嗎?有疑問(wèn)嗎?在評(píng)論中分享您的經(jīng)驗(yàn)!我回復(fù)每條評(píng)論并喜歡看到您的進(jìn)步。
第三部分見!快樂編碼! ???????
以上是《給所有人的權(quán)威 CSS 指南》中的掌握 CSS |第2部分的詳細(xì)內(nèi)容。更多信息請(qǐng)關(guān)注PHP中文網(wǎng)其他相關(guān)文章!
本站聲明本文內(nèi)容由網(wǎng)友自發(fā)貢獻(xiàn),版權(quán)歸原作者所有,本站不承擔(dān)相應(yīng)法律責(zé)任。如您發(fā)現(xiàn)有涉嫌抄襲侵權(quán)的內(nèi)容,請(qǐng)聯(lián)系admin@php.cn![]()
熱AI工具
![]()
Undress AI Tool
免費(fèi)脫衣服圖片
![]()
Undresser.AI Undress
人工智能驅(qū)動(dòng)的應(yīng)用程序,用于創(chuàng)建逼真的裸體照片
![]()
AI Clothes Remover
用于從照片中去除衣服的在線人工智能工具。
![]()
Clothoff.io
AI脫衣機(jī)
![]()
Video Face Swap
使用我們完全免費(fèi)的人工智能換臉工具輕松在任何視頻中換臉!
![]()
熱門文章
Agnes Tachyon Build Guide |漂亮的德比志2 周前 By Jack chenOguri Cap Build Guide |漂亮的德比志2 周前 By Jack chenPalia:Rasquellywag的Riches Quest演練4 周前 By DDD峰:如何復(fù)興球員3 周前 By DDDGrass Wonder Build Guide |烏瑪媽媽漂亮的德比1 周前 By Jack chen![]()
熱工具
![]()
記事本++7.3.1
好用且免費(fèi)的代碼編輯器
![]()
SublimeText3漢化版
中文版,非常好用
![]()
禪工作室 13.0.1
功能強(qiáng)大的PHP集成開發(fā)環(huán)境
![]()
Dreamweaver CS6
視覺化網(wǎng)頁(yè)開發(fā)工具
![]()
SublimeText3 Mac版
神級(jí)代碼編輯軟件(SublimeText3)
See all articles什么是'渲染障礙CSS”? Jun 24, 2025 am 12:42 AM
CSS會(huì)阻塞頁(yè)面渲染是因?yàn)闉g覽器默認(rèn)將內(nèi)聯(lián)和外部CSS視為關(guān)鍵資源,尤其是使用引入的樣式表、頭部大量?jī)?nèi)聯(lián)CSS以及未優(yōu)化的媒體查詢樣式。1.提取關(guān)鍵CSS并內(nèi)嵌至HTML;2.延遲加載非關(guān)鍵CSS通過(guò)JavaScript;3.使用media屬性優(yōu)化加載如打印樣式;4.壓縮合并CSS減少請(qǐng)求。建議使用工具提取關(guān)鍵CSS,結(jié)合rel="preload"異步加載,合理使用media延遲加載,避免過(guò)度拆分與復(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)避免使用促進(jìn)性技術(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是一個(gè)根據(jù)目標(biāo)瀏覽器范圍自動(dòng)為CSS屬性添加廠商前綴的工具。1.它解決了手動(dòng)維護(hù)前綴易出錯(cuò)的問(wèn)題;2.通過(guò)PostCSS插件形式工作,解析CSS、分析需加前綴的屬性、依配置生成代碼;3.使用步驟包括安裝插件、設(shè)置browserslist、在構(gòu)建流程中啟用;4.注意事項(xiàng)有不手動(dòng)加前綴、保持配置更新、非所有屬性都加前綴、建議配合預(yù)處理器使用。
什么是CSS計(jì)數(shù)器? Jun 19, 2025 am 12:34 AM
csscounterscanautomationallymentermentermentections和lists.1)usecounter-ensettoInitializize,反插入式發(fā)芽,andcounter()orcounters()
CSS:何時(shí)重要(何時(shí)不)? Jun 19, 2025 am 12:27 AM
在CSS中,選擇器和屬性名不區(qū)分大小寫,而值、命名顏色、URL和自定義屬性則區(qū)分大小寫。1.選擇器和屬性名不區(qū)分大小寫,例如background-color和Background-Color相同。2.值中的十六進(jìn)制顏色不區(qū)分大小寫,但命名顏色區(qū)分大小寫,如red有效而Red無(wú)效。3.URL區(qū)分大小寫,可能導(dǎo)致文件加載問(wèn)題。4.自定義屬性(變量)區(qū)分大小寫,使用時(shí)需注意大小寫一致。
什么是圓錐級(jí)函數(shù)? Jul 01, 2025 am 01:16 AM
theconic-Gradient()functionIncsscreatesCircularGradientsThatRotateColorStopSaroundAcentralPoint.1.IsidealForPieCharts,ProgressIndicators,colordichers,colorwheels和decorativeBackgrounds.2.itworksbysbysbysbydefindefingincolordefingincolorstopsatspecificains off.
![]()