\/* 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 參考文獻(xiàn):\n<\/h3>\n\n
\n
- \nMDN Web ドキュメント - CSS カスタム プロパティ (変數(shù)) の使用 - CSS 変數(shù)の定義、使用、更新に関する例を示した、初心者向けの徹底した説明です。<\/li>\n
- \nW3Schools - CSS 変數(shù) - 簡(jiǎn)単な練習(xí)用のライブ コード例を使用して CSS 変數(shù)の基本をカバーします。<\/li>\n
- \nCSS のトリック - カスタム プロパティの完全ガイド - 実際の使用例と高度な変數(shù)の使用に関するヒントを紹介する包括的なガイドです。<\/li>\n
- \nFreecodecamp - CSS 変數(shù)フル ハンドブック - カスケード効果、メディア クエリベースの変數(shù)、スコープ管理などの強(qiáng)力なテクニックを探ります。<\/li>\n<\/ul>\n\n\n
\n\n\n \n \n アニメーションとトランジション \n<\/h2>\n\n
Web サイトに動(dòng)きを加えると、魅力的なユーザー エクスペリエンスが生まれます。 CSS では、アニメーションを作成する主な方法が 2 つあります:<\/p>\n\n
\n \n \n トランジション\n<\/h3>\n\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 キーフレームアニメーション\n<\/h3>\n\n
より複雑な複數(shù)ステップのアニメーションの場(chǎ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 高度なアニメーション技術(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 高度なキーフレーム アニメーション:\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 參考文獻(xiàn):\n<\/h3>\n\n
\n
- \nMDN Web ドキュメント - CSS トランジション - CSS トランジションの明確な入門書であり、スタイルを変更するときにスムーズな効果を作成する方法を説明しています。<\/li>\n
- \nMDN Web ドキュメント - CSS アニメーション - キーフレーム、アニメーション プロパティ、複雑なアニメーションの作成に関するステップバイステップ ガイド。<\/li>\n
- \nW3Schools - CSS トランジション - トランジションとアニメーションをインタラクティブに練習(xí)できるライブ コード エディターを備えた初心者向け。<\/li>\n
- \nW3Schools - CSS アニメーション - キーフレームとトランジションを使用して Web サイトにアニメーションを追加するためのわかりやすいガイドです。<\/li>\n
- \nCSS トリック - アニメーション - 応答性の高いアニメーション、アクセシビリティのためのモーションの削減、メディア クエリの統(tǒng)合について説明します。<\/li>\n
- \nAnimate.css - プロジェクトに簡(jiǎn)単に追加できる、事前に構(gòu)築されたアニメーションを提供する人気の CSS ライブラリです。<\/li>\n<\/ul>\n\n\n
\n\n\n \n \n ベストプラクティスと組織 \n<\/h2>\n\n
\n \n \n CSS アーキテクチャ\n<\/h3>\n\n
\n
- 一貫した命名規(guī)則を使用する<\/li>\n
- コンポーネント\/機(jī)能ごとに 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 アーキテクチャのベスト プラクティス\n<\/h2>\n\n\n\n
\n\n\n <メタ文字セット=\"UTF-8\">\n \nCSS アーキテクチャ演習(xí)<\/title>\n <リンク rel=\"スタイルシート\" href=\"styles\/reset.css\"> \n <リンク rel=\"スタイルシート\" href=\"styles\/layout.css\"> \n <リンク rel=\"スタイルシート\" href=\"styles\/components\/header.css\"> \n <リンク rel=\"スタイルシート\" href=\"styles\/components\/card.css\"> \n <リンク rel=\"スタイルシート\" href=\"styles\/utilities.css\"> \n<\/head>\n\n \n\n\n\n \n \n \n 參考文獻(xiàn):\n<\/h3>\n\n<\/pre>\n
\n
- \nBEM - Block Element Modifier - CSS クラスに名前を付け、スタイルを構(gòu)築して再利用性と保守性を向上させるための一般的な方法論。<\/li>\n
- \nSMACSS - CSS のスケーラブルなモジュラー アーキテクチャ - CSS を論理的で保守可能なカテゴリに編成するための詳細(xì)なフレームワーク。<\/li>\n
- \nCSS ガイドライン (Harry Roberts 著) - 論理ファイル構(gòu)造と命名規(guī)則を備えた、スケーラブルで保守可能な CSS を作成するための高品質(zhì)なガイド。<\/li>\n<\/ul>\n\n\n
\n\n\n \n \n 構(gòu)築する時(shí)間です! ?\n<\/h2>\n\n
今度はあなたが學(xué)んだことを?qū)g踐する番です!あなたの課題は次のとおりです:<\/p>\n
\n
- 新しい CodePen を作成します (codepen.io で無料です)<\/li>\n
- これまでに取り上げた例と演習(xí)を構(gòu)築します<\/li>\n
- \nあなたの作品を共有してください!<\/strong> 以下のコメントに CodePen のリンクをドロップしてください<\/li>\n<\/ul>\n\n
ボーナスポイント<\/strong>: デザインに獨(dú)自のクリエイティブなひねりを加えましょう!コメントで共有されたすべての CodePen を個(gè)人的に確認(rèn)して返信します。<\/p>\n\n
? プロのヒント<\/strong>: 自分の考えを説明するために、CSS にコメントを忘れずに追加してください。他の人があなたのコードから學(xué)ぶのに役立ちます!<\/p>\n\n\n
\n\n\n \n \n 次は何ですか? ?\n<\/h2>\n\n
これは CSS Zero to Hero シリーズのパート 2 です。今後の投稿では、さらにエキサイティングな CSS の概念をさらに詳しく掘り下げていきます。お見逃しのないようにご注意ください:<\/p>\n\n
\n
- ? この投稿をブックマーク<\/strong>すると、コーディング時(shí)にすぐに參照できます<\/li>\n
- ?? 役に立ったと思ったら、この記事にいいね!<\/strong> (他の人も見つけやすくなります!)<\/li>\n
- ? フォローしてください<\/strong> シリーズの次の部分をご覧ください<\/li>\n<\/ol>\n\n
\n \n \n つながろう! ?\n<\/h3>\n\n
エクササイズは試しましたか?ご質(zhì)問がありますか?コメントであなたの経験を共有してください!私はすべてのコメントに返信し、あなたの進(jìn)歩を見るのが大好きです。<\/p>\n\n
パート 3 でお會(huì)いしましょう!コーディングを楽しんでください! ??????<\/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
レスポンシブデザインの原則
今日のマルチデバイスの世界では、レスポンシブ デザインはオプションではなく、不可欠です。あなたのウェブサイトは、スマートフォンで見ても、デスクトップの大きなモニターで見ても、見栄えが良くなければなりません。
メディアクエリ
メディア クエリはレスポンシブ デザインのスーパーパワーです:
/* 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; } }対応ユニット
相対単位を使用すると、デザインが自然に応答性の高いものになります:
- rem: ルート要素のフォント サイズとの相対値
- em: 親要素のフォント サイズを基準(zhǔn)
- vw/vh: ビューポートの寸法を基準(zhǔn)
- %: 親要素のサイズに対する相対値
実踐演習(xí): レスポンシブ サービス セクション
メディア クエリと柔軟なユニットを使用して、さまざまな畫面サイズにシームレスに適応する応答性の高いサービス セクションを作成します。
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: サービス セクションのより具體的なブレークポイントを見てみましょう。
/* 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; } }參考文獻(xiàn):
- MDN Web ドキュメント - レスポンシブ デザインの基礎(chǔ) - ビューポート、ブレークポイント、柔軟なレイアウトをカバーする、レスポンシブ デザインの概念への優(yōu)れた入門書です。
- FreeCodeCamp - レスポンシブ Web デザイン認(rèn)定資格 - レスポンシブ デザインの原則、グリッド、メディア クエリ、アクセシビリティをカバーする完全なコース。
- 使用できますか - メディア クエリやフレックスボックスなどのレスポンシブ デザイン機(jī)能に対するブラウザの互換性を確認(rèn)します。
- レスポンシブ デザインのチートシート - レスポンシブ デザインの主要なプロパティとテクニックを理解しやすい形式でカバーしています。
CSS 変數(shù)とカスタム プロパティ
CSS 変數(shù) (カスタム プロパティ) は、スタイルシートにプログラミングのような柔軟性をもたらします。メンテナンスが容易になり、ダイナミックなスタイリングが可能になります。
:root { --primary-color: #007bff; --secondary-color: #6c757d; --spacing-unit: 1rem; } .button { background-color: var(--primary-color); padding: var(--spacing-unit); }実踐的な演習(xí): テーマと再利用性のための CSS 変數(shù)
<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; }參考文獻(xiàn):
- MDN Web ドキュメント - CSS カスタム プロパティ (変數(shù)) の使用 - CSS 変數(shù)の定義、使用、更新に関する例を示した、初心者向けの徹底した説明です。
- W3Schools - CSS 変數(shù) - 簡(jiǎn)単な練習(xí)用のライブ コード例を使用して CSS 変數(shù)の基本をカバーします。
- CSS のトリック - カスタム プロパティの完全ガイド - 実際の使用例と高度な変數(shù)の使用に関するヒントを紹介する包括的なガイドです。
- Freecodecamp - CSS 変數(shù)フル ハンドブック - カスケード効果、メディア クエリベースの変數(shù)、スコープ管理などの強(qiáng)力なテクニックを探ります。
アニメーションとトランジション
Web サイトに動(dòng)きを加えると、魅力的なユーザー エクスペリエンスが生まれます。 CSS では、アニメーションを作成する主な方法が 2 つあります:
トランジション
単純な狀態(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; } }キーフレームアニメーション
より複雑な複數(shù)ステップのアニメーションの場(chǎ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; } }高度なアニメーション技術(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; } }高度なキーフレーム アニメーション:
: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; } }參考文獻(xiàn):
- MDN Web ドキュメント - CSS トランジション - CSS トランジションの明確な入門書であり、スタイルを変更するときにスムーズな効果を作成する方法を説明しています。
- MDN Web ドキュメント - CSS アニメーション - キーフレーム、アニメーション プロパティ、複雑なアニメーションの作成に関するステップバイステップ ガイド。
- W3Schools - CSS トランジション - トランジションとアニメーションをインタラクティブに練習(xí)できるライブ コード エディターを備えた初心者向け。
- W3Schools - CSS アニメーション - キーフレームとトランジションを使用して Web サイトにアニメーションを追加するためのわかりやすいガイドです。
- CSS トリック - アニメーション - 応答性の高いアニメーション、アクセシビリティのためのモーションの削減、メディア クエリの統(tǒng)合について説明します。
- Animate.css - プロジェクトに簡(jiǎn)単に追加できる、事前に構(gòu)築されたアニメーションを提供する人気の CSS ライブラリです。
ベストプラクティスと組織
CSS アーキテクチャ
- 一貫した命名規(guī)則を使用する
- コンポーネント/機(jī)能ごとに 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 アーキテクチャのベスト プラクティス
<!DOCTYPE html> <html lang="ja"> <メタ文字セット="UTF-8"> <meta name="viewport" content="width=device-width、initial-scale=1.0"> <title>CSS アーキテクチャ演習(xí)</title> <リンク rel="スタイルシート" href="styles/reset.css"> <!-- デフォルトのブラウザスタイルをリセットします --> <リンク rel="スタイルシート" href="styles/layout.css"> <!-- レイアウト関連のスタイル --> <リンク rel="スタイルシート" href="styles/components/header.css"> <!-- ヘッダーコンポーネントのスタイル --> <リンク rel="スタイルシート" href="styles/components/card.css"> <!-- カード コンポーネント スタイル --> <リンク rel="スタイルシート" href="styles/utilities.css"> <!-- クイックフィックス用のユーティリティ クラス --> </head> <h3> 參考文獻(xiàn): </h3>
- BEM - Block Element Modifier - CSS クラスに名前を付け、スタイルを構(gòu)築して再利用性と保守性を向上させるための一般的な方法論。
- SMACSS - CSS のスケーラブルなモジュラー アーキテクチャ - CSS を論理的で保守可能なカテゴリに編成するための詳細(xì)なフレームワーク。
- CSS ガイドライン (Harry Roberts 著) - 論理ファイル構(gòu)造と命名規(guī)則を備えた、スケーラブルで保守可能な CSS を作成するための高品質(zhì)なガイド。
構(gòu)築する時(shí)間です! ?
今度はあなたが學(xué)んだことを?qū)g踐する番です!あなたの課題は次のとおりです:
- 新しい CodePen を作成します (codepen.io で無料です)
- これまでに取り上げた例と演習(xí)を構(gòu)築します
- あなたの作品を共有してください! 以下のコメントに CodePen のリンクをドロップしてください
ボーナスポイント: デザインに獨(dú)自のクリエイティブなひねりを加えましょう!コメントで共有されたすべての CodePen を個(gè)人的に確認(rèn)して返信します。
? プロのヒント: 自分の考えを説明するために、CSS にコメントを忘れずに追加してください。他の人があなたのコードから學(xué)ぶのに役立ちます!
次は何ですか? ?
これは CSS Zero to Hero シリーズのパート 2 です。今後の投稿では、さらにエキサイティングな CSS の概念をさらに詳しく掘り下げていきます。お見逃しのないようにご注意ください:
- ? この投稿をブックマークすると、コーディング時(shí)にすぐに參照できます
- ?? 役に立ったと思ったら、この記事にいいね! (他の人も見つけやすくなります!)
- ? フォローしてください シリーズの次の部分をご覧ください
つながろう! ?
エクササイズは試しましたか?ご質(zhì)問がありますか?コメントであなたの経験を共有してください!私はすべてのコメントに返信し、あなたの進(jìn)歩を見るのが大好きです。
パート 3 でお會(huì)いしましょう!コーディングを楽しんでください! ??????
以上が誰でも使える決定版 CSS ガイドで CSS をマスターする |パート2の詳細(xì)內(nèi)容です。詳細(xì)については、PHP 中國語 Web サイトの他の関連記事を參照してください。
このウェブサイトの聲明この記事の內(nèi)容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰屬します。このサイトは、それに相當(dāng)する法的責(zé)任を負(fù)いません。盜作または侵害の疑いのあるコンテンツを見つけた場(chǎng)合は、admin@php.cn までご連絡(luò)ください。![]()
ホットAIツール
![]()
Undress AI Tool
脫衣畫像を無料で
![]()
Undresser.AI Undress
リアルなヌード寫真を作成する AI 搭載アプリ
![]()
AI Clothes Remover
寫真から衣服を削除するオンライン AI ツール。
![]()
Clothoff.io
AI衣類リムーバー
![]()
Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡(jiǎn)単に交換できます。
![]()
人気の記事
Agnes Tachyonビルドガイド|かなりのダービーズメソム2週間前 By Jack chenOguri Cap Build Guide |かなりのダービーズメソム2週間前 By Jack chenすべての日付:ダークとハーパーの関係ガイド1 か月前 By Jack chen砂丘:目覚め - 高度な惑星科醫(yī)クエストウォークスルー4週間前 By Jack chenPalia:RasquellywagのRiches Questウォークスルー4週間前 By DDD![]()
ホットツール
![]()
メモ帳++7.3.1
使いやすく無料のコードエディター
![]()
SublimeText3 中國語版
中國語版、とても使いやすい
![]()
ゼンドスタジオ 13.0.1
強(qiáng)力な PHP 統(tǒng)合開発環(huán)境
![]()
ドリームウィーバー CS6
ビジュアル Web 開発ツール
![]()
SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)
![]()
ホットトピック
Gmailメールのログイン入り口はどこですか?8640
17
Java チュートリアル1786
16
CakePHP チュートリアル1729
56
Laravel チュートリアル1581
29
PHP チュートリアル1448
31
See all articles「レンダリングブロッキングCSS」とは何ですか? Jun 24, 2025 am 12:42 AM
ブラウザは、特にインポートされたスタイルシート、ヘッダーのインラインCSS、および最適化されていないメディアクエリスタイルを使用して、ブラウザがインラインおよび外部CSSをデフォルトで主要なリソースとして表示するため、ページレンダリングをブロックします。 1.重要なCSSを抽出し、HTMLに埋め込みます。 2。JavaScriptを介して非クリティカルなCSSの読み込みを遅らせる。 3.メディア屬性を使用して、印刷スタイルなどのロードを最適化します。 4.リクエストを減らすためにCSSを圧縮およびマージします。ツールを使用してキーCSSを抽出し、REL = "Preload"非同期負(fù)荷を組み合わせ、過度の分割と複雑なスクリプト制御を避けるためにメディア遅延荷重を合理的に使用することをお?jiǎng)幛幛筏蓼埂?/p>
外部対內(nèi)部CSS:最良のアプローチは何ですか? Jun 20, 2025 am 12:45 AM
TheBestAppRoachforCSDependsonTheProject'sSpecificNeeds.forLargerProjects、externalCssissisbetterduetoMaintainasiladability; forsmallerProjectsOrsingLe-PageApplications、internalcsSmightBemoresuitable.it
CSSケース感度:重要なことを理解する Jun 20, 2025 am 12:09 AM
cssismostlycase-inssensitive、buturlsandfontfamilynamesarecase-sensitive.1)propertiesandvalueslikecolor:red; areotcase-sensitive.2)urlsmustmatchtheserver'scase、例えば、/畫像/logo.png.3)
Autoprefixerとは何ですか?それはどのように機(jī)能しますか? Jul 02, 2025 am 01:15 AM
Autoprefixerは、ターゲットブラウザスコープに基づいてCSS屬性にベンダープレフィックスを自動(dòng)的に追加するツールです。 1.エラーで接頭辭を手動(dòng)で維持する問題を解決します。 2. PostCSSプラグインフォーム、CSSを解析し、プレフィックスする必要がある屬性を分析し、構(gòu)成に従ってコードを生成する屬性を分析します。 3.使用手順には、プラグインのインストール、ブラウザーリストの設(shè)定、ビルドプロセスでそれらを有効にすることが含まれます。 4。メモには、接頭辭を手動(dòng)で追加しない、構(gòu)成の更新を保持すること、すべての屬性ではなくプレフィックスを維持することが含まれ、プリ??プロセッサでそれらを使用することをお?jiǎng)幛幛筏蓼埂?/p>
CSSカウンターとは何ですか? Jun 19, 2025 am 12:34 AM
csScountersCantAnationally-bersectionSandLists.1)usecounter-resettoinitialize、counter-incrementtoincrease、andcounter()orcounters()todisplayvalues.2)を組み合わせたjavascriptfordynamiccontenttoensureaCurateupdatesと組み合わせます。
CSS:ケースはいつ重要ですか(いつそうではありませんか)? Jun 19, 2025 am 12:27 AM
CSSでは、セレクターと屬性名はケースに敏感ですが、値、名前の色、URL、およびカスタム屬性はケースに敏感です。 1.バックグラウンドカラーや背景色など、セレクターと屬性名はケース非感受性です。 2。値の16進(jìn)數(shù)色は大文字と小文字を區(qū)別しますが、赤と赤などの名前の色は無効です。 3. URLは癥例に敏感であり、ファイルロードの問題を引き起こす可能性があります。 4.カスタムプロパティ(変數(shù))はケースに敏感であり、使用する場(chǎng)合はケースの一貫性に注意を払う必要があります。
conic-gradient()関數(shù)とは何ですか? Jul 01, 2025 am 01:16 AM
TheConic-Gradient()functionsscreateScular勾配の勾配は、測(cè)定されていることを確認(rèn)してください
![]()