clip 僅適用於 position: absolute 元素,且已被 clip-path 取代。現代開發請直接使用 clip-path。
.clipped {
position: absolute; /* 必須 */
clip: rect(top, right, bottom, left);
/* 或 */
clip: rect(10px, 100px, 50px, 20px); /* 上右下左,相對元素左上角 (0,0) */
}
auto 表示該邊不裁切clip-path 無需定位、支援任意形狀、動畫、SVG 路徑,是現代標準。
.circle { clip-path: circle(50% at center); }
.ellipse { clip-path: ellipse(50% 30% at 50% 50%); }
.polygon { clip-path: polygon(0 0, 100% 0, 100% 75%, 50% 100%, 0 75%); }
.inset { clip-path: inset(10px 20px 30px 40px round 8px); } /* 矩形可圓角 */
<svg width="0" height="0">
<defs>
<clipPath id="star-shape">
<polygon points="50,0 61,35 98,35 68,57 79,94 50,75 21,94 32,57 2,35 39,35" />
</clipPath>
</defs>
</svg>
.star { clip-path: url(#star-shape); }
transition: clip-path 0.5s 實現展開/收合、掃光效果background-clip: text 實現漸層文字 (配合 color: transparent).panel {
clip-path: inset(0 0 100% 0); /* 完全隱藏 */
transition: clip-path 0.4s ease-out;
}
.panel.open {
clip-path: inset(0 0 0 0); /* 完全顯示 */
}
css-clip-path-polyfill (僅支援基本形狀)