- CSS 教程
- CSS - 首页
- CSS - 路线图
- CSS - 简介
- CSS - 语法
- CSS - 选择器
- CSS - 包含
- CSS - 测量单位
- CSS - 颜色
- CSS - 背景
- CSS - 字体
- CSS - 文本
- CSS - 图片
- CSS - 链接
- CSS - 表格
- CSS - 边框
- CSS - 块级边框
- CSS - 内联边框
- CSS - 外边距
- CSS - 列表
- CSS - 内边距
- CSS - 光标
- CSS - 轮廓
- CSS - 尺寸
- CSS - 滚动条
- CSS - 内联块
- CSS - 下拉菜单
- CSS - 可见性
- CSS - 溢出
- CSS - Clearfix
- CSS - 浮动
- CSS - 箭头
- CSS - 调整大小
- CSS - 引号
- CSS - 顺序
- CSS - 位置
- CSS - 连字符
- CSS - 悬停
- CSS - 显示
- CSS - 聚焦
- CSS - 缩放
- CSS - 转换
- CSS - 高度
- CSS - 连字符字符
- CSS - 宽度
- CSS - 不透明度
- CSS - Z-Index
- CSS - 底部
- CSS - 导航栏
- CSS - 覆盖层
- CSS - 表单
- CSS - 对齐
- CSS - 图标
- CSS - 图片库
- CSS - 注释
- CSS - 加载器
- CSS - 属性选择器
- CSS - 组合器
- CSS - 根
- CSS - 盒模型
- CSS - 计数器
- CSS - 剪裁
- CSS - 书写模式
- CSS - Unicode-bidi
- CSS - min-content
- CSS - 全部
- CSS - 内嵌
- CSS - 隔离
- CSS - 滚动溢出
- CSS - Justify Items
- CSS - Justify Self
- CSS - 制表符大小
- CSS - 指针事件
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - 最大块尺寸
- CSS - 最小块尺寸
- CSS - 混合模式
- CSS - 最大内联尺寸
- CSS - 最小内联尺寸
- CSS - 偏移
- CSS - 口音颜色
- CSS - 用户选择
- CSS 高级
- CSS - 网格
- CSS - 网格布局
- CSS - Flexbox
- CSS - 可见性
- CSS - 定位
- CSS - 图层
- CSS - 伪类
- CSS - 伪元素
- CSS - @规则
- CSS - 文本效果
- CSS - 分页媒体
- CSS - 打印
- CSS - 布局
- CSS - 验证
- CSS - 图片精灵
- CSS - 重要
- CSS - 数据类型
- CSS3 教程
- CSS3 - 教程
- CSS - 圆角
- CSS - 边框图片
- CSS - 多背景
- CSS - 颜色
- CSS - 渐变
- CSS - 盒阴影
- CSS - 盒装饰中断
- CSS - 光标颜色
- CSS - 文本阴影
- CSS - 文本
- CSS - 2D 转换
- CSS - 3D 转换
- CSS - 过渡
- CSS - 动画
- CSS - 多列
- CSS - 盒尺寸
- CSS - 工具提示
- CSS - 按钮
- CSS - 分页
- CSS - 变量
- CSS - 媒体查询
- CSS - 函数
- CSS - 数学函数
- CSS - 遮罩
- CSS - 形状
- CSS - 样式图片
- CSS - 特异性
- CSS - 自定义属性
- CSS 响应式
- CSS RWD - 简介
- CSS RWD - 视口
- CSS RWD - 网格视图
- CSS RWD - 媒体查询
- CSS RWD - 图片
- CSS RWD - 视频
- CSS RWD - 框架
- CSS 工具
- CSS - PX 到 EM 转换器
- CSS - 颜色选择器和动画
- CSS 资源
- CSS - 有用资源
- CSS - 讨论
CSS - mask-position 属性
CSS mask-position 属性用于指定元素内遮罩图像的位置。 遮罩图像通常使用 mask-image 属性定义,而 mask-position 允许您控制遮罩图像在元素框内的放置位置,相对于由 mask-origin 属性设置的遮罩位置层。
语法
mask-position: top | right | bottom | left | center | length | percentage | initial | inherit;
属性值
| 值 | 描述 |
|---|---|
|
遮罩的位置使用以下关键字设置:left、right、top、bottom、center。 如果只提供一个值,则另一个值为 center。 |
| 长度 (xpos, ypos) | 第一个值设置水平距离,第二个值设置垂直距离。 左上角为 0 0。 可以使用任何长度单位(例如 px、em、rem 等)。 如果只提供一个值,则另一个值为 50%。 |
| 百分比 (x%, y%) | 第一个值设置水平距离,第二个值设置垂直距离。 左上角为 0% 0%,右下角为 100% 100%。 如果只提供一个值,则另一个值为 50%。 默认值:0% 0% |
| initial | 它将属性设置为其默认值。 |
| inherit | 它从父元素继承属性。 |
CSS Mask Position 属性示例
以下示例说明了使用不同值的 mask-position 属性。
使用关键字值的 Mask Position 属性
要设置遮罩的位置,我们可以使用关键字值:left、right、top、center 和 bottom。 最多接受两个值。 如果指定了两个值,则第一个值设置水平距离,第二个值设置垂直距离。 如果只给出一个值,则另一个值取为 center。 以下示例中显示了这些内容。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.container {
border: 2px solid;
height: 400px;
width: 450px;
}
.mask {
-webkit-mask-image: url(/css/images/logo.png);
mask-image: url(/css/images/logo.png);
mask-size: 50%;
mask-repeat: no-repeat;
}
.ex1 {
mask-position: left center;
}
.ex2 {
mask-position: center;
}
.ex3 {
mask-position: right top;
}
</style>
</head>
<body>
<h2>
CSS mask-position Property
</h2>
<h4>
mask-position: left center (two values- define x
position and y position repectively)
</h4>
<div class="container">
<div class="mask ex1">
<img src="/css/images/scenery.jpg"
alt="img" width="600" height="400">
</div>
</div>
<h4>
mask-position: center (single value, the
second value is also center)
</h4>
<div class="container">
<div class="mask ex2">
<img src="/css/images/scenery.jpg"
alt="img" width="600" height="400">
</div>
</div>
<h4>
mask-position: right top (two values- define x
position and y position repectively)
</h4>
<div class="container">
<div class="mask ex3">
<img src="/css/images/scenery.jpg"
alt="img" width="600" height="400">
</div>
</div>
</body>
</html>
使用长度值的 Mask Position 属性
要设置遮罩的位置,我们可以使用长度单位(例如 px、em、rem 等)指定位置。 最多接受两个值。 如果指定了两个值,则第一个值设置水平距离,第二个值设置垂直距离。 如果只给出一个值,则另一个值取为 50%。 以下示例中显示了这些内容。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.container {
border: 2px solid;
height: 400px;
width: 450px;
}
.mask {
-webkit-mask-image: url(/css/images/logo.png);
mask-image: url(/css/images/logo.png);
mask-size: 50%;
mask-repeat: no-repeat;
}
.ex1 {
mask-position: 70px 90px;
}
.ex2 {
mask-position: 7em 14em;
}
</style>
</head>
<body>
<h2>
CSS mask-position Property
</h2>
<h4>
mask-position: 70px 90px (70px from left
edge and 90px from top edge)
</h4>
<div class="container">
<div class="mask ex1">
<img src="/css/images/scenery.jpg"
alt="img" width="600" height="400">
</div>
</div>
<h4>
mask-position: 7em 14em (7em from the left
edge and 14em from top edge)
</h4>
<div class="container">
<div class="mask ex2">
<img src="/css/images/scenery.jpg"
alt="img" width="600" height="400">
</div>
</div>
</body>
</html>
使用百分比值的 Mask Position 属性
要设置遮罩的位置,我们可以使用相对于容器大小的百分比值(例如 10%)指定位置。 最多接受两个值。 如果指定了两个值,则第一个值设置水平距离,第二个值设置垂直距离。 如果只给出一个值,则另一个值取为 50%。 以下示例中显示了这些内容。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.container {
border: 2px solid;
height: 400px;
width: 450px;
}
.mask {
-webkit-mask-image: url(/css/images/logo.png);
mask-image: url(/css/images/logo.png);
mask-size: 50%;
mask-repeat: no-repeat;
}
.ex1 {
mask-position: 70% 30%;
}
.ex2 {
mask-position: 50%;
}
</style>
</head>
<body>
<h2>
CSS mask-position Property
</h2>
<h4>
mask-position: 70% 30% (70% from left edge and 30% from
the top edge relative to the container height and width)
</h4>
<div class="container">
<div class="mask ex1">
<img src="/css/images/scenery.jpg"
alt="img" width="600" height="400">
</div>
</div>
<h4>
mask-position: 50% ( second value is also 50%, 50% from
the left edge and 50% from the top edge relative to the
container height and width)
</h4>
<div class="container">
<div class="mask ex2">
<img src="/css/images/scenery.jpg"
alt="img" width="600" height="400">
</div>
</div>
</body>
</html>
支持的浏览器
| 属性 | ![]() |
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|---|---|
| mask-position | 120 | 120 | 53 | 15.4 | 106 |
css_properties_reference.htm
广告




