0

I'm attempting to create a card with a transform: skew(-30deg);. My goal is to have the card split into twos color similar to this example : enter image description here

I am able to create the photo when it's the entire background in play. Here is a jsfiddle example.

But when trying to add the same effect inside of a card it is having no effect. I've attempted to add the same CSS properties in the first fiddle as a pseudo-element for the class that is determining the card background. At the moment it has no effect on the card background, the card's background is still completely blue ( in the jsfiddle link below) . How can I add this effect to the card?

Here is a code snippet of my current code:

.card {
  background: blue;
}

.card::after{
  
  position: fixed;
    top: 0px;
    left: 0px;
    width: 70%;
    height: 100%;
    background-color: white;
    z-index: 1;
    transform: skew(-30deg);
    transform-origin:top;
  }
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css" rel="stylesheet"/>

  <div class="row">
    <div class="col">
      <div class="card">
        <div class="card-content black-text">
          <span class="card-title">Card Title</span>
          <p>I am a very simple card. I am good at containing small bits of information.
          I am convenient because I require little markup to use effectively.</p>
        </div>
      </div>
    </div>
  </div>

I am expecting the same skew effect in the photo above presented inside of the card. Where there is an angled blue background with the rest being white. Here is a jsfiddle with the code for the card: https://jsfiddle.net/3cntLx5u/10/

maimok
  • 333
  • 1
  • 3
  • 12
  • (1) missing `content:""` and (2) use position:absolute on pseudo element and position:relative on the card element – Temani Afif Sep 14 '20 at 23:52

1 Answers1

1

This should be a step in the right direction: https://jsfiddle.net/3cntLx5u/10/

Your main issue was your position which was fixed and you were missing content in your ::after selector!

body{
  background-color: #000;
}

.card {
  background: blue;
}

.card::after{
 content: '';
 position: absolute;
 top: 0px;
 left: 0px;
 width: 70%;
 height: 100%;
 background-color: white;
 z-index: 1;
 transform: skew(-30deg);
 transform-origin:top;
 }
Dylan Anlezark
  • 1,256
  • 2
  • 12
  • 27