简体   繁体   English

固定位置背景剪辑文本

[英]Fixed position background-clip for text

Is it possible to keep background-clipped image (in a text) at fixed location? 是否可以在固定位置保留背景剪裁图像(文本中)?

You can see an example here http://codepen.io/anon/pen/WQzpWQ 你可以在http://codepen.io/anon/pen/WQzpWQ看到一个例子

css: CSS:

.text {
  background: url(http://publicdomainarchive.com/wp-content/uploads/2014/05/public-domain-images-free-stock-photos-tree-blossoms-bench-1-1000x666.jpg);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

As you see, the background-clip works however for every text it's a new image. 如您所见,背景剪辑适用于每个文本,它是一个新图像。 What ı like to do instead is a single background image (fullscreen) that will be seen through the text background-clip's as we scroll down. 相反,我喜欢做的是单个背景图像(全屏),当我们向下滚动时,将通过文本背景剪辑看到它。

Looking for a solution 寻找解决方案

Try this out, I've added some extra attributes to the background property to achieve the full-screen effect and set the background-size to cover - 试试这个,我在background属性中添加了一些额外的属性来实现全屏效果并设置background-size来覆盖 -

.text{
    background: url(http://publicdomainarchive.com/wp-content/uploads/2014/05/public-domain-images-free-stock-photos-tree-blossoms-bench-1-1000x666.jpg) fixed center center no-repeat;
    background-size: cover;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

CodePen Example CodePen示例

Edit 编辑

If you want a teardown of all the added values inside the background , here what it would look like by setting those with defined attribute names. 如果您想要在background拆除所有添加的值,请在此处设置具有已定义属性名称的值。

.text{
    background: url(http://publicdomainarchive.com/wp-content/uploads/2014/05/public-domain-images-free-stock-photos-tree-blossoms-bench-1-1000x666.jpg);
    background-attachment: fixed;
    background-position: center center;
    background-repeat: no-repeat;
    background-size: cover;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

Your .text class should look like this one: 您的.text类应如下所示:

.text {
  background: url(http://publicdomainarchive.com/wp-content/uploads/2014/05/public-domain-images-free-stock-photos-tree-blossoms-bench-1-1000x666.jpg);
  background-size: cover;
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-clip: text;
  color: transparent;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM