【发布时间】:2014-01-28 02:09:28
【问题描述】:
我正在尝试绘制这个特殊的形状:
它必须有两个直面,除了半圆之外,我无法创造出更好的形状。是否可以用 CSS 从圆圈中减去这些部分,还是应该直接从 .psd 文件中提取图像?
【问题讨论】:
-
这当然可以。等待更好的答案。
标签: html css shapes css-shapes
我正在尝试绘制这个特殊的形状:
它必须有两个直面,除了半圆之外,我无法创造出更好的形状。是否可以用 CSS 从圆圈中减去这些部分,还是应该直接从 .psd 文件中提取图像?
【问题讨论】:
标签: html css shapes css-shapes
在属性之后使用 css 来做:
#circle {
width: 100px;
height: 100px;
}
#circle:after {
width: 100px;
height: 100px;
background: red;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
border-radius: 50px;
display: block;
content: '';
position: absolute;
top: -5px;
left: -5px;
}
在 html 中:
<div id="circle"></div>
【讨论】:
position: relative; 添加到#circle 并将circle:after 的左上角替换为right: 15px; bottom: 15px
我接受了汤姆的回答,并在 div 中添加了溢出:隐藏。
这样就不用在body的边框上设置div了
CSS
#circle {
position: relative;
left: 40px;
top: 40px;
width: 100px;
height: 100px;
overflow: hidden;
}
#circle:after {
width: 100px;
height: 100px;
background: red;
border-radius: 50%;
display: block;
content: '';
position: absolute;
top: -20px;
left: -5px;
}
【讨论】:
HTML
<div id="circle"> </div>
CSS
#circle {
width: 100px;
height: 100px;
background: red;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
border-radius: 50px;
}
输出:
更新的 CSS
#circle {
width: 400px;
height: 400px;
background: red;
-webkit-border-top-left-radius: 80px;
-webkit-border-top-right-radius: 100px;
-webkit-border-bottom-right-radius: 200px;
-webkit-border-bottom-left-radius: 200px;
}
在 Chrome 中检查,Updated Fiddle
输出:
【讨论】: