1. 面向开发者的 Web 技术
  2. CSS:层叠样式表
  3. CSS 参考
  4. 属性
  5. clip

此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

clip

已弃用: 不再推荐使用该特性。虽然一些浏览器仍然支持它,但也许已从相关的 web 标准中移除,也许正准备移除或出于兼容性而保留。请尽量不要使用该特性,并更新现有的代码;参见本页面底部的兼容性表格以指导你作出决定。请注意,该特性随时可能无法正常工作。

clip 属性定义了元素的哪一部分是可见的。clip 属性只适用于 position:absolute 的元素。

警告:这个属性已被废弃。建议使用 clip-path

语法

css
/* 关键字值 */
clip: auto;
/* <shape> 值 */
clip: rect(1px, 10em, 3rem, 2ch);
/* 全局值 */
clip: inherit;
clip: initial;
clip: revert;
clip: revert-layer;
clip: unset;

<shape>

一个矩形 <shape>

css
rect(<top>, <right>, <bottom>, <left>) /* 标准语法 */

css
rect(<top> <right> <bottom> <left>) /* 向后兼容语法 */

<top><bottom> 指定相对于盒子上边框边界 的偏移,<right><left> 指定了相对于盒子左边框边界 的偏移。 <top><right><bottom><left> 的值可以是 <length> 值或 auto

auto

元素不裁剪 (默认值)

形式定义

初始值 auto
适用元素绝对定位元素
是否是继承属性
计算值 auto if specified as auto, otherwise a rectangle with four values, each of which is auto if specified as auto or the computed length otherwise
动画类型 a rectangle

形式语法

clip = 
<rect()> |
auto

<rect()> =
rect( <top> , <right> , <bottom> , <left> )

示例

裁剪图像

HTML

html
<p class="dotted-border">
 <img src="macarons.png" title="Original graphic" />
 <img id="top-left" src="macarons.png" title="Graphic clipped to upper left" />
 <img id="middle" src="macarons.png" title="Graphic clipped towards middle" />
 <img
 id="bottom-right"
 src="macarons.png"
 title="Graphic clipped to bottom right" />
</p>

CSS

css
.dotted-border {
 border: dotted;
 position: relative;
 width: 390px;
 height: 400px;
}
#top-left,
#middle,
#bottom-right {
 position: absolute;
 top: 0;
}
#top-left {
 left: 400px;
 clip: rect(0, 130px, 90px, 0);
}
#middle {
 left: 270px;
 clip: rect(100px, 260px, 190px, 130px);
}
#bottom-right {
 left: 140px;
 clip: rect(200px, 390px, 290px, 260px);
}

结果

规范

规范
CSS Masking Module Level 1
# propdef-clip

浏览器兼容性

参见

帮助改进 MDN

了解如何参与贡献

此页面最后更新于 ,由 MDN 贡献者更新。

AltStyle によって変換されたページ (->オリジナル) /