Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
334 views
in Technique[技术] by (71.8m points)

html - CSS Shape Wave Divider with the Body Background SVG Texture

I'm using https://www.shapedivider.app/ to create a wave shape for a div box. However I don't have a solid fill color on the element behind it, I have a color with a svg background texture. How can I get my wave to have the same svg texture as my body background?

It's missing the body svg texture background: https://i.imgur.com/1OoUt6H.png

On the body, I'm using a https://www.heropatterns.com/

Example code of the problem:

<head>
    <style>
        body {
        background-color: #0b4a34;
        background-image: url("data:image/svg+xml,%3Csvg width='40' height='40' viewBox='0 0 40 40' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0h20v20H0V0zm10 17a7 7 0 1 0 0-14 7 7 0 0 0 0 14zm20 0a7 7 0 1 0 0-14 7 7 0 0 0 0 14zM10 37a7 7 0 1 0 0-14 7 7 0 0 0 0 14zm10-17h20v20H20V20zm10 17a7 7 0 1 0 0-14 7 7 0 0 0 0 14z' fill='%23ffffff' fill-opacity='0.06' fill-rule='evenodd'/%3E%3C/svg%3E");
}

.custom-shape-divider-top-1611477509 {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    overflow: hidden;
    line-height: 0;
}

.custom-shape-divider-top-1611477509 svg {
    position: relative;
    display: block;
    width: calc(100% + 1.3px);
    height: 112px;
}

.custom-shape-divider-top-1611477509 .shape-fill {
    fill: #0b4a34;
}
</style></head>
<body>
<section style="position: relative;">
<div class="custom-shape-divider-top-1611477509">
    <svg data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 120" preserveAspectRatio="none">
        <path d="M321.39,56.44c58-10.79,114.16-30.13,172-41.86,82.39-16.72,168.19-17.73,250.45-.39C823.78,31,906.67,72,985.66,92.83c70.05,18.48,146.53,26.09,214.34,3V0H0V27.35A600.21,600.21,0,0,0,321.39,56.44Z" class="shape-fill"></path>
    </svg>
</div>
<div style="margin-top: 50px;background-color: #fff;height: 300px;">
    test
</div>
</section>
</body>

Paste into https://codepen.io/pen/

question from:https://stackoverflow.com/questions/65869014/css-shape-wave-divider-with-the-body-background-svg-texture

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I've changed slightly the shape you have. I'm keeping the curve but I close the shape in the opposite direction. All a stroke to see what I mean.

The shape is filled white leaving the rest of the svg transparent so that you can see the body's background.

 body {
        background-color: #0b4a34;
        background-image: url("data:image/svg+xml,%3Csvg width='40' height='40' viewBox='0 0 40 40' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0h20v20H0V0zm10 17a7 7 0 1 0 0-14 7 7 0 0 0 0 14zm20 0a7 7 0 1 0 0-14 7 7 0 0 0 0 14zM10 37a7 7 0 1 0 0-14 7 7 0 0 0 0 14zm10-17h20v20H20V20zm10 17a7 7 0 1 0 0-14 7 7 0 0 0 0 14z' fill='%23ffffff' fill-opacity='0.06' fill-rule='evenodd'/%3E%3C/svg%3E");
}


svg {
    position: relative;
    display: block;
    width: calc(100% + 1.3px);
    height: 112px;
    background:transparent;
}
<section style="position: relative;">

    <svg data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 120" preserveAspectRatio="none">
        <path d="M0,27.35 A600.21,600.21,0,0,0,321.39,56.44
                 C379.39,45.65,435.545,26.31,493.39,14.58
                 C575.78,-2.14,661.58,-3.15,743.84,14.19
                 C823.78,31,906.67,72,985.66,92.83
                 C1055.71,111.31,1132.19,118.92,1200,95.83V120H0Z" class="shape-fill" fill="white"></path>
    </svg>

<div style="margin-top: 0px;background-color: white;height: 300px;">
    test
</div>
</section>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...