2

I want to create an overlay with css over one image like this: enter image description here

but I only do a square overlay like this: enter image description here

how I can make the first shape with css ??

here is my code:

.card-img-overlay {
position: absolute;
top: 0px;
right: 0px;
bottom: 0;
left: 150px;
padding: 1.25rem;
}

thank you for your answers :)

Temani Afif
  • 245,468
  • 26
  • 309
  • 415
  • Use the rotation method as explained [here] (https://stackoverflow.com/questions/14233341/how-can-i-rotate-an-html-div-90-degrees) – GalAbra Feb 08 '18 at 23:20
  • 1
    You can use plenty of things: From CSS `linear-gradient` background, CSS `:before` with border, CSS `transform` and `rotate`, CSS3 -`clip-path` and `polygon`, painted `canvas` shape, SVG... So many options - yet you tried none? Or did you? What was your google research and which one you tried? – Roko C. Buljan Feb 08 '18 at 23:25

2 Answers2

5

Check this out

#triangle-topleft {
  width: 0;
  height: 0;
  border-top: 100px solid #9020d1bb;
  border-left: 100px solid transparent;
  position: absolute;
}

#container {
  position: relative;
}

#container #triangle-topleft,
#overlay {
  position: absolute;
  color: white;
  right: 0;
}
<div id="container">
  <div id="triangle-topleft"></div>
  <div id="overlay">Microsoft</div>
</div>
Yatrix
  • 13,361
  • 16
  • 48
  • 78
Battlesquid
  • 302
  • 1
  • 10
1

I will go with a simple gradient and no need for any extra markup or the use of pseudo element:

body {
  height: 100vh;
  margin: 0;
  background: 
  linear-gradient(to top right, transparent 50%, rgba(255, 0, 0, 0.5) 51%) 0 0/100% 200px no-repeat, 
  url(https://lorempixel.com/1000/1000/) center/cover;
}
div {
 height:200px;
 text-align:right;
 color:#fff;
 padding:10px;
 font-size:25px;
}
<div>
  <p>Some content</p>
</div>
Temani Afif
  • 245,468
  • 26
  • 309
  • 415
  • How can we place some text inside the RED area , If I add some more controls it looks like the shape is breaking – Sebastian Jan 27 '22 at 21:41