Slant the top of a div using css without skewing text

前端 未结 1 1739
死守一世寂寞
死守一世寂寞 2020-12-03 01:42

I am trying to create a div that slants only at the top and does not skew the text within it, using CSS. The reason I would like for it to be CSS-only is because it is a res

相关标签:
1条回答
  • 2020-12-03 02:29

    Skew the box one way, and its contents the other:

    <aside class="skew-neg">
        <div class="skew-pos">
            <p>Hello World.</p>
            <p>@jonathansampson.</p>
            <p>This box is skewed.</p>
            <p>In supported browsers.</p>
        </div>
    </aside>
    
    /* Skew the container one way */
    .skew-neg {
        -webkit-transform: skewY(-5deg);
        -moz-transform: skewY(-5deg);
        -ms-transform: skewY(-5deg);
        -o-transform: skewY(-5deg);
        transform: skewY(-5deg);
    }
    
    /* And the child another way */
    .skew-pos {
        -webkit-transform: skewY(5deg);
        -moz-transform: skewY(5deg);
        -ms-transform: skewY(5deg);
        -o-transform: skewY(5deg);
        transform: skewY(5deg);
    }
    

    Which results in something similar to the following:

    enter image description here

    Demo: http://jsfiddle.net/Q7dKT/191/

    0 讨论(0)
提交回复
热议问题