How to make a curve on a rectangle's top in css? only in top edge

限于喜欢 提交于 2019-12-12 00:58:40

问题


I want to create the following shape:

Important: if I use "Border Radius" I get this (and I do not want this result):


回答1:


Here are DEMO

HTML:

<div id="gray">
    <div id="red"></div>
</div>

CSS:

#gray{

  height: 100%;
  background-color: #ccc;
  overflow: hidden;  
}

#red{

  width: 150%;
  height: 150%;
  background-color: #f00;
  border-radius: 100%;
  top: 50%;
  left: -25%;
  right: 0;
  position: relative;
}



回答2:


Something like this would be roughly equivalent:

http://jsfiddle.net/ny4Q9/

css:

.curvetop {
    position: relative;
    margin-top: 80px;
    background: red;
    width: 100%;
    height: 400px;
    z-index: 1;
}

.curvetop:after {
    top: -80px;
    display: block;
    position: absolute;
    content: '';
    border-radius: 50%;
    background: red;
    width: 100%;
    height: 170px;
}

markup:

<div class="curvetop"></div>

By using border-radius with a value of 50% you can create a circle.. which, as per your question you can attach to the top of another element by way of a pseudo element.




回答3:


You can use border radius

http://jsfiddle.net/wULyB/

<div id="out">
    <div id="in"></div>

</div>

CSS

#out{
    width: 100px;
    height: 100px;
    overflow: hidden;
    background: green;
    position: relative;
}
#in{
    width: 200px;
    height: 200px;
    border-radius: 100px;
    background: black;
    position: absolute;
    left: -50px;
    top: 30px;
}

You can play around with the numbers but you get the idea



来源:https://stackoverflow.com/questions/21764144/how-to-make-a-curve-on-a-rectangles-top-in-css-only-in-top-edge

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