A way to curve (outside) an element in CSS3

自闭症网瘾萝莉.ら 提交于 2021-01-28 18:30:30

问题


I'm trying to curve an element and then add a background-image property in it. I was looking on this question - Is there a way to curve an element?. The only difference, is that I want it to be curved outside.

Here's an example:

This is what I tried to do: http://jsfiddle.net/KcmfC/1148/

The problem in this result is that it's too much curved. I can't find any solution for this.

#test {
  background: url('http://www.planwallpaper.com/static/images/i-should-buy-a-boat.jpg') repeat center center / cover;
  border: 0px solid #000;
  width: 100%;
  min-height: 15em;
  border-radius: 0 0 100% 100%;
}
<div id="test"></div>

回答1:


The thing I did is a bit tricky, I stretched the width to 140% and the I "cut" the edges via overflow: hidden. Here's my full example:

#test {
  position: relative;
  overflow: hidden;
  min-height:  150px;
}
#test:before {
    background: url('http://www.planwallpaper.com/static/images/i-should-buy-a-boat.jpg') repeat center center / 1048px 319px;
    border: 0px solid #000;
    content: "";
    width: 140%;
      height: 100%;
    border-radius: 0 0 100% 100%;
    position: absolute;
    z-index: -1;
    left: -20%;
    right: -20%;
}
<div id="test">
  <div>
 SOME TEXT SOME TEXT SOME 
  </div>
</div>



回答2:


You can use a pseudo element

div {
  background: gray url(http://www.planwallpaper.com/static/images/i-should-buy-a-boat.jpg) no-repeat center bottom -25px / cover;
  height: 180px;
  position: relative;      
}
div:after {
  content: '';
  background: gray url(http://www.planwallpaper.com/static/images/i-should-buy-a-boat.jpg) no-repeat center bottom / cover;
  border-radius: 50%;
  width: 100%;
  height: 50px;
  top: calc(100% - 25px);
  left:0;
  position: absolute;
}
<div></div>



回答3:


reduice the border radius pourentage

body{
  margin:0
    }

#test {
    background: url('http://www.planwallpaper.com/static/images/i-should-buy-a-boat.jpg') repeat center center / cover;
    border: 0px solid #000;
    width: 100%;
    min-height: 15em;
    border-radius: 0 0 35% 35%;
}
<div id="test">
</div>



回答4:


What about this?

#test {
  background: url('http://www.planwallpaper.com/static/images/i-should-buy-a-boat.jpg') repeat center center / cover;
  border: 0px solid #000;
  width: 100%;
  min-height: 15em;
  border-radius: 0 0 70% 70% / 20%;
}
<div id="test"></div>


来源:https://stackoverflow.com/questions/38171941/a-way-to-curve-outside-an-element-in-css3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!