Create slope full width css3

后端 未结 1 1945
后悔当初
后悔当初 2021-01-15 01:37

I\'m trying to create a slope/diagonal with SVG (first time, other alternatives accepted) and im having a lot of issues with it. My goal is:

  • Create a full widt
相关标签:
1条回答
  • 2021-01-15 01:55

    If you're open to a css solution you could do something like this:

    Demo here: http://jsfiddle.net/jme11/D9M2L/

    CSS

    body {
        background-color: #000;
        margin: 0px;
    }
    p {
        color: white;
    }
    section {
        position: relative;
        background: blue;
        color: #fff;
        text-align: center;
    }
    section:before {
        position: absolute;
        content:'';
    }
    section.diagonal {
        background: blue;
    }
    footer {
        position: relative;
        background: black;
        color: #fff;
        text-align: center;
    }
    footer:before {
        position: absolute;
        content:'';
    }
    footer.diagonal {
        background: black;
    }
    .diagonal {
        z-index: 1;
        padding: 3em;
    }
    .diagonal:before {
        -webkit-transform: rotate(-3deg);
        transform: rotate(-3deg);
        -webkit-transform-origin: 3% 0;
        transform-origin: 3% 0;
        top: 0;
        left: -25%;
        z-index: -1;
        width: 150%;
        height: 75%;
        background: inherit;
    }
    

    HTML:

    <header>
        <p>Header</p>
    </header>
    <section class="diagonal">
        <p>Lorem ipsum</p>
        <p>Lorem ipsum</p>
        <p>Lorem ipsum</p>
        <p>Lorem ipsum</p>
        <p>Lorem ipsum</p>
        <p>Lorem ipsum</p>
    </section>
    <footer class="diagonal">
        <p>Footer</p>    
    </footer>
    

    If you want support for IE9 add the ms- prefix for the transform: http://caniuse.com/#search=transform

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