1

can someone help me to get effect like this? the background image needs to be deleted using text like image given below. with css enter image description here

Salil Rajkarnikar
  • 588
  • 1
  • 7
  • 26

1 Answers1

2

You can use background-clip with -webkit-text-fill-color: transparent with a pseudo element.

Place an element with a background image and a position of relative. Then place an element inside that element and cover 50vw of the width 100% of the height of its parent, then position it absolute and place left or right and top @ 0. Then you can set style text as you like. set the background-clip to text, background-clip: text; and set -webkit-text-fill-color: transparent, set background-size to cover on both parent and clip elements.

Now set a pseudo element to place your black background. .clip-area::before set the background to black, width to 50% and height to 100%, left or right and top to 0 and z-index to -1.

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

#bg {
  width: 100vw;
  height: 100vw;
  background: url(https://d2jx2rerrg6sh3.cloudfront.net/image-handler/ts/20200123101248/ri/673/picture/2020/1/shutterstock_603198743.jpg) no-repeat;
  position: relative;
  z-index: 1;
  background-size: cover;
}

.clip-area {
  display: flex;
  align-items: center;
  position: absolute;
  left: 0;
  top: 0;
  width: 50vw;
  height: 100%;
  line-height: 3.5rem;
  font-size:  clamp(2rem, 3.5vw, 5rem);
  text-align: center;
  text-transform: uppercase;
  font-family: 'Open Sans Pro', sans-serif;
  font-weight: bold;
  background: url(https://d2jx2rerrg6sh3.cloudfront.net/image-handler/ts/20200123101248/ri/673/picture/2020/1/shutterstock_603198743.jpg);
  background-size: cover;
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.clip-area::before {
  content: '';
  background: black;
  width: 50vw;
  height: calc(100% - 6px);
  position: absolute;
  left: 0;
  top: 0;
  z-index: -1;
  margin: 3px;
  border-top-left-radius: 1rem;
  border-bottom-left-radius: 1rem;
}
<div id="bg">
  <div class="clip-area">
    You can use text clipping to show the background below
  </div>
</div>
dale landry
  • 7,831
  • 2
  • 16
  • 28