Effect on css image

Asked

Viewed 627 times

2

How do I do this effect like in this css image ?

inserir a descrição da imagem aqui

2 answers

2


I made an example using the pseudo class ::after, so you have no problem when doing the effect on the element in which your content is inside. To create this tilt I used the transform:skew and I used flexbox to keep everything in line.

See the result in the example below:

.container {
    display: flex;
    position: relative;
    width: 500px;
    height: 300px;
    background-image: url(http://unsplash.it/500/300);
    background-size: cover;
    overflow: hidden;
    flex-direction: row-reverse;
    align-items: center;
    box-sizing: border-box;
    padding-right: 3rem;
}
.container::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
    background-color: rgba(0,0,0,0.5);
    transform: skew(-30deg) translateX(calc(50% + 3rem));
}
.cont {
    font-family: sans-serif;
    color: #fff;
    z-index: 99;
}
<div class="container">
    <div class="cont">
        <h1>Meu texto</h1>
        <p>texto texto</p>
        <button>BTN</button>
    </div>
</div>

1

To create this effect, just use transform: skewX(-18deg); in the element you want to create the tilt effect.

Example:

* { padding: 0; margin: 0 }

.container {
  background:blue;
  background-size: cover;
  height: 149.8px;
  overflow:hidden;
  width: 314px;
}

/* Elemento inclinado */
.overlay {
  background: #00000050;
  height: 100%;
  width: 65%;
  margin-left: 46%;
  transform: skewX(-18deg);
  overflow:hidden;
}

h1, span {
  color:#FFF;
  display:block;
  margin: 30px;
  transform: skewX(18deg);
}
span {
  margin-top: -20px;
}
<div class="container">
  <div class="overlay">
    <h1>Title</h1>
    <span>Description</span>
  </div>
</div>

Reference: https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/skew

You can also use a background gradient to do this effect. Simply add background: linear-gradient(107deg, transparent 20%, green 20%); in the element you want, for example:

* { padding: 0; margin: 0 }

.container {
  background:blue;
  background-size: cover;
  height: 149.8px;
  overflow:hidden;
  width: 314px;
}

/* Elemento inclinado */
.overlay {
  background: linear-gradient(107deg, transparent 20%, green 20%);
  float:right;
  height: 100%;
  padding-left: 20px;
  width: 60%;
  overflow:hidden;
}

h1, span {
  color:#FFF;
  display:block;
  margin: 30px;
}
span {
  margin-top: -20px;
}
<div class="container">
  <div class="overlay">
    <h1>Title</h1>
    <span>Description</span>
  </div>
</div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.