我正在尝试使用纯CSS实现以下功能,是否可能?如果我能找到一种方法将底部部分隐藏到可以工作的底部圆角的顶部。但我迷失了会发挥作用......
.ribbon, .ribbon * {
box-sizing: border-box;
-moz-box-sizing: border-box;
}
.ribbon {
width: 600px;
margin: 40px auto 10px;
padding: 0 10px 4px;
position: relative;
color: black;
background: #eee;
}
.ribbon h3 {
display: block;
height: 40px;
width: 620px;
margin: 0;
padding: 5px 10px 5px 30px;
position: relative;
left: -30px;
color: white;
background: rgb(193,0,0);
box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.ribbon h3::before {
content: '';
display: block;
width: 0;
height: 0;
position: absolute;
bottom: -11px;
z-index: 10;
left: 0;
}
.ribbon.round h3 {
border-radius: 10px 0px 0px 0px;
}
.ribbon.round h3::before {
width: 20px;
height: 30px;
bottom: -20px;
border: none;
background: rgb(61,0,0);
border-radius: 10px 0px 0px 10px;
}
摆弄我目前所拥有的东西 http://jsfiddle.net/yoderman94/Gdgwq/
答案 0 :(得分:4)
只需将z-index
值设为负值:
.ribbon h3::before {
z-index: -1;
}
这将把它放在标题下。
要保持圆顶,请添加另一个z-index较低的块,并使用与标题相同的背景填充它:
答案 1 :(得分:3)
这是一个新的小提琴,它像99%那里(仅在Chrome中测试过),需要更多地使用阴影。 http://jsfiddle.net/jrTAA/2/
.ribbon.round h3 {
border-radius: 5px 0px 0px 0px;
}
.ribbon.round h3::before, .ribbon.round h3::after {
width: 20px;
height: 8px;
bottom: -8px;
border: none;
border-top:2px solid rgb(193,0,0);
border-left:1px solid rgb(193,0,0);
border-bottom:1px solid rgb(193,0,0);
background: rgb(61,0,0);
border-radius: 5px 0px 0px 5px;
box-shadow: 0 1px 2px rgba(0,0,0,0.3), inset 2px 1px 2px rgba(0,0,0,0.3);
}
答案 2 :(得分:2)
小提琴: http://jsfiddle.net/aleation/gCrhQ/
代码:
.ribbon, .ribbon * {
box-sizing: border-box;
-moz-box-sizing: border-box;
}
.ribbon {
width: 600px;
margin: 40px auto 10px;
padding: 0;
position: relative;
color: black;
background: #eee;
}
.ribbon h3 {
display: block;
height: 40px;
width: 100%;
margin: 0;
padding: 9px 0 0 10px;
color: white;
background: rgb(193,0,0);
box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.ribbon h3::before,
.ribbon p::before{
content: '';
display: block;
width: 0;
height: 0;
position: absolute;
bottom: -11px;
z-index: 10;
left: 0;
width: 14px;
}
/* Round */
.ribbon.round h3::before{
height: 45px;
top: 0px;
left: -14px;
border: none;
background: rgb(193,0,0);
border-top-left-radius: 7px 4px;
}
.ribbon.round p::before{
height: 7px;
top: 40px;
left: -14px;
border: none;
background: rgb(61,0,0);
border-top-left-radius: 7px 4px;
border-bottom-left-radius: 7px 4px;
}
.ribbon p{
margin: 0;
padding: 20px;
}