2

我有一个元素,我只想在元素的末尾屏蔽它。我设法编写了一些代码来屏蔽元素的结尾,但元素的其余部分现在也被屏蔽了。我想更改遮罩,以便遮罩左侧的所有元素仍然可见。

.masked {
  width: 300px;
  height: 30px;
  background-color: hotpink;
  mask-image: linear-gradient(to right, black, transparent);
  mask-size: 30px;
  mask-repeat: no-repeat;
  mask-position: right;
}
<div class="masked"></div>

4

1 回答 1

3

你需要多个面具

.masked {
  width: 300px;
  height: 30px;
  background-color: hotpink;
  -webkit-mask: 
    linear-gradient(black 0 0)                    left,
    linear-gradient(to right, black, transparent) right;
  -webkit-mask-size:
    calc(100% - 30px) 100%,
    30px              100%;
  -webkit-mask-repeat: no-repeat;
}
<div class="masked"></div>

或者您调整一个蒙版,如下所示:

.masked {
  width: 300px;
  height: 30px;
  background-color: hotpink;
  -webkit-mask: linear-gradient(to right, black calc(100% - 30px), transparent);
}
<div class="masked"></div>

另一种语法:

.masked {
  width: 300px;
  height: 30px;
  background-color: hotpink;
  -webkit-mask: 
    linear-gradient(to left , black, transparent) right/30px 100% no-repeat,
    linear-gradient(black 0 0);
  -webkit-mask-composite:destination-out;
  mask-composite:exclude;
}
<div class="masked"></div>

于 2020-08-19T10:00:30.393 回答