【问题标题】:Blur background Image but not the shape on that image模糊背景图像,但不是该图像上的形状
【发布时间】:2021-03-15 20:06:57
【问题描述】:

有三个重要的事情:

  1. 背景图片
  2. 背景图片上的矩形形状
  3. 矩形内的文字

背景图片,考虑一本书,上面有一些标题,并且标题与书的中心对齐。 假设我在该文本上绘制了一个矩形形状,以便文本可以适合矩形形状。 我只想模糊矩形外的区域,以便正确看到矩形内的区域。 那么有没有可能做到……?

类似这样的东西:Sample Image url

<div class="container>

   <div class="shape"></div>

   <img src="image url" ></img>

</div>

【问题讨论】:

标签: javascript html jquery css frontend


【解决方案1】:

.container{
  width: 700px;
  height: 500px;
  position: relative;
}
.container:after{
  content: '';
  position:absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:     url("https://cdn.pixabay.com/photo/2015/06/19/21/24/the-road-815297_960_720.jpg");
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  z-index: 0;
  filter: blur(10px);
}
.shape{
  position:absolute;
  top: 50%;
  left: 50%;
  width: 50%;
  height: 50%;
  transform: translate(-50%, -50%);
  
  background:     url("https://cdn.pixabay.com/photo/2015/06/19/21/24/the-road-815297_960_720.jpg");
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index:1;
}
.shape p{
  color: white;
  font-size: 22px;
  text-transform: uppercase;
}
<div class="container">
   <div class="shape">
    <p>Text inside Rectangle</p>
   </div>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-08
    • 2018-10-06
    • 2013-08-15
    • 2018-02-13
    • 1970-01-01
    相关资源
    最近更新 更多