如何创建与背景渐变和重叠透明形状一起使用的嵌入弯曲背景? [英] How can I create an inset curved background that works with a background gradient and overlapping transparent shapes?

查看:15
本文介绍了如何创建与背景渐变和重叠透明形状一起使用的嵌入弯曲背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用 CSS 来创建如下图所示的网页部分.我不知道如何在背景的顶部和底部创建曲线并保持透明覆盖层的完整性.上面和下面的部分(部分显示)也使用透明背景.所以,你会看到圆圈有不同的阴影.

I have been trying to create a section of a webpage that looks like the image below with just CSS. I can not figure out how to create the curves the top and bottom of the background and keep intact the transparent overlays. The section above and below (partially shown) also use transparent backgrounds. So, you see the different shades the circles have.

推荐答案

这是我尝试的方法.可能需要一些技巧才能使其适用于您的网站,但希望您能看到我使用的技术.

Here is how I would attempt it. It will probably take a bit of finessing to make it work for your site, but hopefully you can see the technique I used.

基本上,您使用 div 作为内容的背景并将它们转换为覆盖.然后将任何内容放在一个容器中,您可以更改 z-index 以高于其他所有内容.曲线本身只是 50% 的边界半径,并且比高度更宽.那么内容的父 div 就有了渐变色背景.

Basically you are using divs as the background to content and translating them to overlay. Then putting any content in a container that you can change the z-index on to bring above everything else. The curve itself is just a border-radius of 50% and skewed wider than tall. Then the content's parent div has the gradient color background.

不过,我确实喜欢 Temani 解决方案的简单性.

I do like the simplicity of Temani's solution though.

/* top ellipse */
.top {
  border-radius: 50%;
  width: 150%;
  height: 200px;
  transform: translate(-15%, 20%);
  background: white;
}

/* content's parent container */
.mid {
  padding: 4rem;
  background: linear-gradient(-20deg, #3adecf, #3ae3c5);
}

.content {
  position: relative;
  z-index: 20;
  color: white;
  font-size: 30px;
}

/* bottom ellipse */
.bottom {
  border-radius: 50%;
  width: 200%;
  height: 200px;
  transform: translate(-25%, -20%);
  background: white;
}

.all {
  overflow-y: hidden;
  position: relative;
}

.t-circle {
  background: #00ccdd;
  position: absolute;
  top: 5%;
  right: -200px;
  z-index: 10;
  width: 400px;
  height: 400px;
  border-radius: 50%;
  opacity: 0.2;
  pointer-events: none;
}

<div class="all">
  <div class="top">Top</div>
  <div class="mid">
    <div class="content">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sapien mauris, efficitur in nisi vel, gravida mollis urna. Praesent ac sem vitae neque pretium ultricies. Vestibulum id mattis neque. Nullam ultricies neque eget metus volutpat, et tempus magna commodo. Phasellus accumsan lacus nibh, at commodo elit pellentesque at. Morbi iaculis bibendum massa, sit amet accumsan felis ullamcorper a. Praesent luctus odio vel tortor finibus feugiat. Sed luctus finibus nisl, in pellentesque orci efficitur ut. Curabitur suscipit elementum aliquam. Sed vel convallis urna.
      <br><br>
        Phasellus porttitor blandit ornare. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam elementum rhoncus diam ac rhoncus. Nunc sed lorem porttitor, placerat sem vitae, bibendum nunc. Ut dolor mi, condimentum vitae leo in, suscipit maximus risus. Morbi consequat dui eros, sit amet dapibus urna porta tempor. Fusce mollis a velit nec auctor. Donec semper elementum feugiat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Pellentesque vel turpis pellentesque, ultricies metus blandit, interdum nibh. Duis malesuada dolor lacus, quis tempor erat elementum in. Pellentesque at consequat nisl. Vestibulum vel urna nec ipsum interdum pellentesque id nec magna. Mauris eu lectus posuere, aliquet justo id, pharetra nisl. 
      </div>
    </div>
  <div class="bottom">bottom</div>
  <div class="t-circle"></div>
</div>

这篇关于如何创建与背景渐变和重叠透明形状一起使用的嵌入弯曲背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆