search

Home  >  Q&A  >  body text

How to add multiple transparent overlays to an image using CSS

How to press the triangle and include the content on top of the white circle? I'm trying to find a solution to create a hero section with a background image that contains three overlay shapes as part of the image. On top of the overlay will be h1, p and btn. I've included a screenshot below showing how the design will look.

There are three overlays:

  1. Rectangular shape, bottom transparency is 0%.
  2. An outer circle with transparency.
  3. Inner circle with transparency.

This is what I have so far. I've included a snippet below, and there's also a working version on Codepen. The circle is in the correct position in the lower left corner.

*{
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
svg {
  width: 628;
  height: 628:
}
.element {  
  position: relative;
  width: 100%;
  min-height: 628px;
  background: url(https://images-prod.healthline.com/hlcmsresource/images/AN_images/health-benefits-of-apples-1296x728-feature.jpg) no-repeat center top;
  background-size: cover;
}
.element:before{
  content: '';
  position: absolute; bottom: 0; left: 0;
  width: 100%;0
  -webkit-clip-path: polygon(0 0, 0% 100%, 100% 100%);
  clip-path: polygon(0 0, 0% 100%, 100% 100%);
}
.circle-outer {
  cx: 200;
  cy: 720;
  fill: #fff;
  fill-opacity: 0.6;
  r: 420;
  w: 628;
  h: 628;
}
.circle-inner {
  cx: 200;
  cy: 720;
  fill: #fff;
  fill-opacity: 0.6;
  r: 400;
}
.hero-triangle {
  content: '';
  position: relative; 
  width: 100%;
  height: 100px;
  background: #fff;
  -webkit-clip-path: polygon(0 8%, 0% 100%, 100% 100%);
  clip-path: polygon(0 80%, 0% 100%, 100% 100%);
  z-index: 99;
}
<div class="container">
  <div class="element">
    <div class="hero-content">
    <h1>This belongs in circle</h1>
    <p>This belongs in circle too.</p>
    <button class="btn btn-primary">Learn more</button>
    </div>
    <svg viewbox width="1000" height="580" viewBox="0 0 100 100">
      <circle class="circle-outer" />
      <circle class="circle-inner" />
      <polygon points="0,0 0,200 1000,200" style="fill:#fff;" />
    </svg>
  </div>
</div>
<div class="container">
  <h4>Body content must be positioned right underneath hero image for all widths.</h4>

P粉777458787P粉777458787273 days ago423

reply all(1)I'll reply

  • P粉610028841

    P粉6100288412024-02-26 12:55:44

    Since circles are only decorative and do not add meaning, there is no need for them to be elements. They are sufficient as background images.

    This is a simple code snippet that places a content element and gives it two background images, both with some transparency, using a radial gradient to make them round.

    .element {
      position: relative;
      width: 100%;
      rmin-height: 628px;
      background: url(https://images-prod.healthline.com/hlcmsresource/images/AN_images/health-benefits-of-apples-1296x728-feature.jpg) no-repeat center top;
      background-size: cover;
      clip-path: polygon(0 0, 0 80%, 100% 100%, 100% 0);
      aspect-ratio: 1296 / 728;
    }
    
    .hero-content {
      position: absolute;
      left: -12.5%;
      top: 50%;
      width: 70%;
      padding-top: 5%;
      box-sizing: border-box;
      aspect-ratio: 1 / 1;
      background-image: radial-gradient(circle, rgba(255, 255, 255, 0.8) 0 65%, transparent 65% 100%), radial-gradient(circle, rgba(255, 255, 255, 0.2) 0 70% , transparent 70% 100%);
      background-repeat: no-repeat;
      background-size: 100% 100%;
      display: flex;
      align-items: center;
      rjustify-content: center;
      flex-direction: column;
    }
    
    .hero-content h1 {
      font-size: 2vw;
    }
    
    .hero-content p {
      font-size: 1vw;
    }
    
    .hero-content button {
      font-size: 1vw;
    }

    This belongs in circle

    This belongs in circle too.

    Body content must be positioned right

    Note: Obviously you will need to change the settings for font size to suit your specific use case. I just make them relative to the viewport so that it's responsive.

    Also, I think there is some confusion between whether the hero has to cover the entire width or set a minimum height. Of course, if this is what is desired, the circles will be in a different position relative to the apple, and some of the image may disappear.

    reply
    0
  • Cancelreply