<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>CSS Clip-Path: Shaping Web Elements</title> <style> body { font-family: sans-serif; } .container { display: flex; justify-content: center; align-items: center; min-height: 100vh; } .intro-image { width: 500px; height: auto; } .section-title { font-size: 1.5em; font-weight: bold; margin-bottom: 1em; } .code-example { background-color: #f0f0f0; padding: 1em; border-radius: 5px; margin-bottom: 1em; overflow-x: auto; /* Add horizontal scroll if needed */ } .code-example pre { margin: 0; } .image-example { display: flex; justify-content: center; align-items: center; margin-bottom: 2em; } .image-example img { max-width: 100%; height: auto; } .key-takeaway { margin-bottom: 2em; } .key-takeaway ul { list-style-type: disc; padding-left: 20px; } .faq-section { margin-top: 3em; } .faq-section h2 { font-size: 1.8em; font-weight: bold; margin-bottom: 1em; } .faq-section .faq-item { margin-bottom: 1em; } .faq-section .faq-item h3 { font-weight: bold; margin-bottom: 0.5em; } </style> </head> <body> <div class="container"> <img src="/static/imghwm/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/174009775169997.jpg?x-oss-process=image/resize,p_40" class="lazy" alt="Introducing the CSS clip-path Property " /> </div> <p>The web's predominantly rectangular layout contrasts with print media's diverse shapes. This difference stems partly from a lack of suitable tools. This tutorial introduces <code>clip-path</code>, a CSS property offering the design flexibility of print.</p> <div class="key-takeaway"> <h2 id="Key-Takeaways">Key Takeaways</h2> <ul> <li><code>clip-path</code> masks parts of an element, exceeding the limitations of the deprecated <code>clip</code> property (rectangular clipping only).</li> <li>It supports basic shapes, geometry boxes, or SVG <code><clippath></code> URLs for complex shapes and animations.</li> <li>Animating <code>clip-path</code> requires matching vertex counts in initial and final shapes for smooth transitions.</li> <li>While not universally supported, major modern browsers (Chrome, Safari, Opera) support <code>clip-path</code> (often with prefixes). Firefox support is partial.</li> </ul> </div> <h2 id="The-Basics">The Basics</h2> <p>Clipping trims parts of an element, partially or fully hiding it. The <i>clipping path</i> defines the visible region, whether a simple shape or a complex polygon. The <i>clipping region</i> is the area within this path. Anything outside is hidden, including backgrounds, borders, shadows, and events.</p> <p>Even with non-rectangular elements, surrounding content flows naturally. For shape-aware content flow, use the <code>shape-outside</code> property (see related SitePoint tutorial).</p> <p>Remember: <code>clip-path</code> differs from the limited, deprecated <code>clip</code> property.</p> <h2 id="Syntax-and-Usage">Syntax and Usage</h2> <p>The syntax is: <code>clip-path: <clip-source> | [<basic-shape> || <geometry-box>] | none</code></p> <ul> <li><code><clip-source></code>: An SVG <code><clippath></code> URL.</li> <li><code><basic-shape></code>: Basic shape functions (CSS Shapes spec).</li> <li><code><geometry-box></code>: (Optional) Reference box for <code><basic-shape></code>, or defines the clipping shape itself (e.g., <code>margin-box</code>).</li> </ul> <div class="code-example"> <pre class="brush:php;toolbar:false"><code>img { clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); }
これは菱形を作成します。頂点座標(x、y)は、要素のボックスに対して時計回りです。

geometry-box
でクリッピングします
<code>.clip-me { clip-path: polygon(10% 20%, 20% 30%, 50% 80%) margin-box; margin: 10%; } </code>
ここで、margin-box
は参照です。 svg要素はfill-box
、stroke-box
、またはview-box
。
clip-path
の使用
clip-path
テキストと画像を強化します。 複雑な形状は簡単に達成できます。

<code>.p-msg { clip-path: polygon(0% 0%, 100% 0%, 100% 75%, 75% 85%, 75% 100%, 50% 80%, 0% 75%); } </code>
画像ギャラリーとアバターは、非長方形の形状の恩恵を受けています。
<code>.right { clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); position: relative; top: -352px; left: 256px; } </code>
アニメーションの追加
アニメーションclip-path
、しかし、一貫した頂点数を維持してスムーズな遷移を維持します。
<code>@keyframes polygons { 25% { clip-path: polygon(20% 0%, 100% 38%, 70% 90%, 0% 100%); } 50% { clip-path: polygon(0 46%, 100% 15%, 55% 74%, 0 100%); } 70% { clip-path: polygon(100% 38%, 100% 38%, 66% 100%, 0 53%); } } </code>
ieとエッジにはサポートがありません。 Firefoxには部分的なサポートがあります(
構文、フラグを介して有効になる可能性があります)。 Chrome、Safari、およびOperaには、url()
プレフィックスが必要です。 最新情報には-webkit-
を使用できますか?
結論
clip-path
よくある質問(FAQ)
CSSクリップパスプロパティとは何ですか?
CSSクリップパスでポリゴン関数を使用するにはどうすればよいですか?clip-path
レスポンシブデザインにCSSクリップパスプロパティを使用できますか?polygon()
clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%)
はい、要素のサイズでスケーリングするために形状パラメーターの割合を使用します。
CSSクリップパスプロパティをアニメーション化することは可能ですか?
はい、キーフレームとanimation
プロパティを使用します。 滑らかな遷移のために頂点数を一貫して保持します
ほとんどの最新のブラウザはそれをサポートしています(更新に使用できますか)。
円を作成します。 たとえば、circle(radius at position)
は要素内の円を中心にします
clip-path: circle(50% at 50% 50%)
以上がCSSクリップパスプロパティの導入の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

CSSグリッドは、複雑で応答性の高いWebレイアウトを作成するための強力なツールです。設計を簡素化し、アクセシビリティを向上させ、古い方法よりも多くの制御を提供します。

記事では、レスポンシブデザインにおけるスペースの効率的なアラインメントと分布のためのレイアウト方法であるCSS FlexBoxについて説明します。 FlexBoxの使用量を説明し、CSSグリッドと比較し、ブラウザのサポートを詳細に説明します。

この記事では、ビューポートメタタグ、柔軟なグリッド、流体メディア、メディアクエリ、相対ユニットなど、CSSを使用してレスポンシブWebサイトを作成するための手法について説明します。また、CSSグリッドとフレックスボックスを使用してカバーし、CSSフレームワークを推奨しています

この記事では、要素の寸法の計算方法を制御するCSSボックスサイズのプロパティについて説明します。コンテンツボックス、ボーダーボックス、パディングボックスなどの値と、レイアウト設計とフォームアライメントへの影響について説明します。

記事では、CSS、キープロパティ、およびJavaScriptとの組み合わせを使用してアニメーションの作成について説明します。主な問題は、ブラウザの互換性です。

記事では、3D変換、主要なプロパティ、ブラウザの互換性、およびWebプロジェクトのパフォーマンスに関する考慮事項にCSSを使用して説明します。

この記事では、CSSグラデーション(線形、放射状、繰り返し)を使用して、ウェブサイトのビジュアルを強化し、深さ、フォーカス、および現代の美学を追加します。

記事では、CSSの擬似要素、HTMLスタイリングの強化における使用、および擬似クラスとの違いについて説明します。実用的な例を提供します。


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

EditPlus 中国語クラック版
サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません

SecLists
SecLists は、セキュリティ テスターの究極の相棒です。これは、セキュリティ評価中に頻繁に使用されるさまざまな種類のリストを 1 か所にまとめたものです。 SecLists は、セキュリティ テスターが必要とする可能性のあるすべてのリストを便利に提供することで、セキュリティ テストをより効率的かつ生産的にするのに役立ちます。リストの種類には、ユーザー名、パスワード、URL、ファジング ペイロード、機密データ パターン、Web シェルなどが含まれます。テスターはこのリポジトリを新しいテスト マシンにプルするだけで、必要なあらゆる種類のリストにアクセスできるようになります。

MinGW - Minimalist GNU for Windows
このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。

WebStorm Mac版
便利なJavaScript開発ツール

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

ホットトピック









