目次
Key Takeaways
The Basics
Syntax and Usage
geometry-box
clip-path
アニメーションの追加
CSSクリップパスプロパティをアニメーション化することは可能ですか?
関数を使用してsvg
ははるかに汎用性があります。
ホームページ ウェブフロントエンド CSSチュートリアル CSSクリップパスプロパティの導入

CSSクリップパスプロパティの導入

Feb 21, 2025 am 08:29 AM

<!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/imghw/default1.png"  data-src="https://img.php.cn/upload/article/000/000/000/174009775169997.jpg"  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)は、要素のボックスに対して時計回りです。

Introducing the CSS clip-path Property

geometry-box

でクリッピングします
<code>.clip-me {
  clip-path: polygon(10% 20%, 20% 30%, 50% 80%) margin-box;
  margin: 10%;
}
        </code>
ログイン後にコピー

ここで、margin-boxは参照です。 svg要素はfill-boxstroke-box、またはview-box

を使用します

clip-path

の使用

clip-pathテキストと画像を強化します。 複雑な形状は簡単に達成できます。

Introducing the CSS clip-path Property
<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-を使用できますか? 結論

は、重要なデザインの可能性を提供します。 ClippyやCSS Plantのクリップパスジェネレーターなどのツールは、複雑なポリゴンの作成を簡素化します。

clip-pathよくある質問(FAQ)

CSSクリップパスプロパティとは何ですか?

要素の一部を切り取り、ディスプレイ領域を定義します。基本的な形状、ジオメトリボックス、またはSVGパスを受け入れ、複雑な形状とアニメーションを可能にします。

CSSクリップパスでポリゴン関数を使用するにはどうすればよいですか?clip-path

関数は(x、y)座標ペアを使用して、ポリゴンの頂点を定義します。 たとえば、
ダイヤモンドを作成します

レスポンシブデザインにCSSクリップパスプロパティを使用できますか?polygon() clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%)はい、要素のサイズでスケーリングするために形状パラメーターの割合を使用します。

CSSクリップパスプロパティをアニメーション化することは可能ですか?

はい、キーフレームとanimationプロパティを使用します。 滑らかな遷移のために頂点数を一貫して保持します

CSSクリップパスプロパティをサポートするブラウザは

ほとんどの最新のブラウザはそれをサポートしています(更新に使用できますか)。

CSSクリップパスで円機能を使用するにはどうすればよいですか?

円を作成します。 たとえば、circle(radius at position)は要素内の円を中心にします clip-path: circle(50% at 50% 50%)

はい、

関数を使用してsvg

要素を参照してください。

url() <clippath> CSSのクリップとクリップパスの違いは何ですか?

は非推奨であり、長方形のクリッピングのみをサポートします。

ははるかに汎用性があります。

clip clip-path CSSクリップパスで挿入関数を使用するにはどうすればよいですか?

オプションの丸い角を備えた長方形を作成します。

inset(top right bottom left [round border-radius])単一のCSSクリップパスで複数の形状を使用できますか?

はい、SVGパス構文を使用して
関数を使用しています。

path()

以上がCSSクリップパスプロパティの導入の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

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

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

SASSをより速くするための概念の証明 SASSをより速くするための概念の証明 Apr 16, 2025 am 10:38 AM

新しいプロジェクトの開始時に、SASSコンピレーションは瞬く間に起こります。これは、特にbrowsersyncとペアになっている場合は素晴らしい気分です。

静的フォームプロバイダーの比較 静的フォームプロバイダーの比較 Apr 16, 2025 am 11:20 AM

ここでは、「静的フォームプロバイダー」という用語を埋めてみましょう。あなたはあなたのHTMLを持ってきます

毎週のプラットフォームニュース:HTMLロード属性、主なARIA仕様、およびIFRAMEからShadowDOMへの移動 毎週のプラットフォームニュース:HTMLロード属性、主なARIA仕様、およびIFRAMEからShadowDOMへの移動 Apr 17, 2025 am 10:55 AM

今週のプラットフォームニュースのラウンドアップで、Chromeは、Web開発者のロード、アクセシビリティ仕様、およびBBCの動きのための新しい属性を導入します

セクション要素との取引 セクション要素との取引 Apr 12, 2025 am 11:39 AM

2つの記事がまったく同じ日に公開されました。

マルチサムスライダー:一般的なケース マルチサムスライダー:一般的なケース Apr 12, 2025 am 10:52 AM

この2部構成のシリーズの最初の部分では、2つの親指スライダーを取得する方法を詳しく説明しました。今、私たちは&#039; llが一般的なマルチサンプスのケースを見ていますが、別のものと

HTMLダイアログ要素を使用したいくつかの実践 HTMLダイアログ要素を使用したいくつかの実践 Apr 16, 2025 am 11:33 AM

これは私が初めてHTML要素を見ていることです。私はしばらくの間それを知っていましたが、まだスピンしていませんでした。かなりクールです

Google Fontsをタグ付けし、Goofonts.comを作成する方法 Google Fontsをタグ付けし、Goofonts.comを作成する方法 Apr 12, 2025 pm 12:02 PM

Goofontsは、開発者妻とデザイナーの夫によって署名されたサイドプロジェクトであり、どちらもタイポグラフィの大ファンです。 Googleにタグを付けています

それはすべて頭の中にあります:Reactヘルメットを使用してReact Poweredサイトのドキュメントヘッドを管理する それはすべて頭の中にあります:Reactヘルメットを使用してReact Poweredサイトのドキュメントヘッドを管理する Apr 15, 2025 am 11:01 AM

ドキュメントヘッドはウェブサイトの中で最も魅力的な部分ではないかもしれませんが、それに入るものは間違いなくあなたのウェブサイトの成功にとってそれと同じくらい重要です

See all articles