简体   繁体   English

CSS弯曲背景

[英]CSS Curved Background

I've had a look around and cannot find anyone with a solution for this: 我四处张望,找不到任何可以解决此问题的人:

The issue: A client of mine is looking to have curved bottom sides to certain divs on their page. 问题:我的一位客户希望页面底部的某些div弯曲。 Some backgrounds will have a photo, some will have a subtle pattern (making the use of .PNG images difficult like I've done here: www.bootbro.com 有些背景会带有照片,有些背景会带有微妙的图案(像我在此处所做的那样,很难使用.PNG图像:www.bootbro.com

So far I have this: 到目前为止,我有这个:

Link: http://jsfiddle.net/dg44thbr/1/ 链接: http//jsfiddle.net/dg44thbr/1/

CSS: CSS:

body {
  margin: 0;
}

.alignCenter {
  text-align: center;
}

.padAll {
  padding: 25px;
}

div#banner {
  position: relative;
  background-image: url(http://wearepeak.co.uk/wp-content/uploads/2016/02/testimonial.jpg);
  width: 100%;
  border-bottom-left-radius: 50%;
  border-bottom-right-radius: 50%;
  z-index: 555;
  border-bottom:3px solid red;
}

div#content {
  position: relative;
  background-image: url(http://wearepeak.co.uk/wp-content/uploads/2016/05/ux-787980_1920-1750x750.jpg);
  width: 100%;
  margin-top: -175px;
  border-bottom-left-radius: 50%;
  border-bottom-right-radius: 50%;
  z-index: 444;
  border-bottom:3px solid red;
}

div#section {
  position: relative;
  background-image: url(http://wearepeak.co.uk/wp-content/uploads/2016/07/balloons-1750x500.jpg);
  width: 100%;
  margin-top: -175px;
  border-bottom-left-radius: 50%;
  border-bottom-right-radius: 50%;
  z-index: 333;
  border-bottom:3px solid red;
}

.left {
  float: left;
}

.right {
  float: right;
}

.clear::after {
  clear: both;
  content: "";
  display: table;
}

.container {
  max-width: 500px;
  margin: auto;
}

.curveContent {
  padding-top: 200px;
}

HTML: HTML:

<div id="banner" class="alignCenter padAll">Content here</div>
<div id="content" class="alignCenter padAll">
  <div class="curveContent">
    <p>Content here</p>
    <p>But on another line! Oh no!</p>
    <p>And another line?! What is this>!</p>
  </div>
</div>

<div id="section">
  <div class="container clear">
    <div class="curveContent">
      <div class="left col2">

        <p>Content here</p>
        <p>But on another line! Oh no!</p>
        <p>And another line?! What is this>!</p>
      </div>
      <div class="right col2">
        Right text
      </div>
    </div>
  </div>
</div>

As you can see, the radius changes depending on the height of the div - something out of my control as this will be affected by containing content. 如您所见,半径根据div的高度而变化-某些内容超出了我的控制范围,这将受到包含内容的影响。 Also the borders become thinner when they get to the sides. 当边界到达侧面时,边界也会变细。

Does anyone have any potential solutions for this? 有没有人对此有任何潜在的解决方案?

Thank you 谢谢

Border-radius can take a few static values such as border-radius: 0 0 200px 200px /15px; 边框半径可以采用一些静态值,例如border-radius: 0 0 200px 200px /15px;

 body { margin: 0; } .alignCenter { text-align: center; } .padAll { padding: 25px; } div#banner { position: relative; background-image: url(http://wearepeak.co.uk/wp-content/uploads/2016/02/testimonial.jpg); width: 100%; border-radius: 0 0 200px 200px /15px; z-index: 555; border-bottom:3px solid red; } div#content { position: relative; background-image: url(http://wearepeak.co.uk/wp-content/uploads/2016/05/ux-787980_1920-1750x750.jpg); width: 100%; margin-top: -175px; border-radius: 0 0 200px 200px /15px; z-index: 444; border-bottom:3px solid red; } div#section { position: relative; background-image: url(http://wearepeak.co.uk/wp-content/uploads/2016/07/balloons-1750x500.jpg); width: 100%; margin-top: -175px; border-radius: 0 0 200px 200px /15px; z-index: 333; border-bottom:3px solid red; } .left { float: left; } .right { float: right; } .clear::after { clear: both; content: ""; display: table; } .container { max-width: 500px; margin: auto; } .curveContent { padding-top: 200px; } 
 <div id="banner" class="alignCenter padAll">Content here</div> <div id="content" class="alignCenter padAll"> <div class="curveContent"> <p>Content here</p> <p>But on another line! Oh no!</p> <p>And another line?! What is this>!</p> </div> </div> <div id="section"> <div class="container clear"> <div class="curveContent"> <div class="left col2"> <p>Content here</p> <p>But on another line! Oh no!</p> <p>And another line?! What is this>!</p> </div> <div class="right col2"> Right text </div> </div> </div> </div> 

http://jsfiddle.net/dg44thbr/3/ http://jsfiddle.net/dg44thbr/3/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM