2

我正在尝试使用纯 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/

4

3 回答 3

4

只需让您的z-index价值为负:

.ribbon h3::before {
  z-index: -1;
}

这将把它放在标题下。

为了保持圆形顶部,添加另一个具有较低 z-index 的块,并使用与标题相同的背景填充它:

示例:http: //jsfiddle.net/K7e96/

于 2013-10-23T15:48:15.090 回答
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);
}
于 2013-10-23T16:01:55.197 回答
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;
}
于 2013-10-23T16:19:49.950 回答