
枠から上に少し出たレイアウトのリボンって、プレゼント枠だったり注目してほしい時など結構使うことがあります。
毎回一からコードを書くのが面倒なので自分用のメモとしてまとめました。
このリボンはリボンの端を透明で指定してあるので、背景に柄などがきても問題ありません。
すべてCSSなのでサイトカラーに合わせて色を変えてお使いいただけると思います!
擬似要素:before:afterにcontentプロパティを使用してリボンの端や影をつけてあります。
デモページはこちら
左寄りリボン

HTML
<div class="demo__box">
<div class="demo01__ribbon">
<h3 class="demo01__title">Ribbon</h3>
</div>
</div>
CSS
.demo__box {
position: relative;
display: block;
margin: 0 20px 80px;
padding: 40px 25px 20px;
line-height: 1.4;
background-color: #fff5f5;
}
.demo01__ribbon {
display: inline-block;
margin: 0 0 0 -5px;
padding-top: 8px;
width: 100px;
height: 36px;
position: absolute;
top: -10px;
left: 0;
color: white;
box-sizing: border-box;
background-color: #ff9b9b;
}
.demo01__title {
margin: 0;
padding-left: 25px;
font-weight: bold;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-size: 14px;
font-size: 1.4rem;
}
.demo01__title:before {
position: absolute;
top: 100%;
left: 0;
border: none;
border-right: solid 5px #d57777;
border-bottom: solid 5px transparent;
content: '';
}
.demo01__title:after {
position: absolute;
width: 0;
height: 0;
top: 0;
right: -10px;
z-index: 1;
border-style: solid;
border-width: 18px 10px 18px 0;
border-color: #ff9b9b transparent;
content: '';
}
センターリボン

HTML
<div class="demo__box">
<div class="demo02__inner">
<div class="demo02__ribbon">
<h3 class="demo02__title">Ribbon</h3>
</div>
</div>
</div>
CSS
.demo__box {
position: relative;
display: block;
margin: 0 20px 80px;
padding: 40px 25px 20px;
line-height: 1.4;
background-color: #fff5f5;
}
.demo02__inner {
position: fixed;
width: 245px;
left: calc(50% - 245px/2);
}
.demo02__ribbon {
display: inline-block;
position: absolute;
top: -60px;
text-align: center;
box-sizing: border-box;
}
.demo02__ribbon:before {
content: '';
position: absolute;
width: 20px;
bottom: -10px;
left: -25px;
z-index: 1;
border: 20px solid #ffafaf;
border-left-color: transparent;
border-width: 18px 10px 18px;
}
.demo02__ribbon:after {
content: '';
position: absolute;
width: 20px;
bottom: -10px;
right: -25px;
z-index: 1;
border: 20px solid #ffafaf;
border-right-color: transparent;
border-width: 18px 10px 18px;
}
.demo02__title {
display: inline-block;
position: relative;
margin: 0;
padding: 0 20px;
width: 245px;
line-height: 40px;
font-size: 18px;
font-weight: normal;
color: #fff;
background: #ff9b9b;
box-sizing: border-box;
z-index: 2;
}
.demo02__title:before {
position: absolute;
content: '';
top: 100%;
left: 0;
border: none;
border-bottom: solid 10px transparent;
border-right: solid 15px #d57777;
}
.demo02__title:after {
position: absolute;
content: '';
top: 100%;
right: 0;
border: none;
border-bottom: solid 10px transparent;
border-left: solid 15px #d57777;
}