学習帳

CSSのみで吹き出しを表現

最終更新:


吹き出し(発言)

通常のタイプ。

動作サンプル

これはサンプル文章です

コードサンプル

HTML

<p class="commentBalloon">これはサンプル文章です</p>

CSS

.commentBalloon{
    position: relative;
    margin: 16px;
    padding: 16px;
    border: 5px solid #d0d0d0;
    background-color:#f0f0f0;
    display:inline-block;
}
.commentBalloon:before {
    position: absolute;
    bottom: -20px;
    left: 9px;
    content: "";
    width: 0;
    height: 0;
    border-bottom: 16px solid transparent;
    border-left: 16px solid #d0d0d0;
}

吹き出し(思考)

上記を元にした応用編。
考えている内容を表現する時の吹き出し。

動作サンプル

これはサンプル文章です

コードサンプル

HTML

<p class="commentBubble">これはサンプル文章です</p>

CSS

.commentBubble{
    position: relative;
    margin: 16px;
    padding: 16px;
    border: 5px solid #d0d0d0;
    background-color:#f0f0f0;
    display:inline-block;
    border-radius:30px;
    z-index:3;
}
.commentBubble:before {
    position: absolute;
    bottom: -20px;
    left: 6px;
    content: "";
    width: 18px;
    height: 12px;
    border: 4px solid #d0d0d0;
    background-color:#f0f0f0;
    border-radius:15px;
    z-index:2;
}
.commentBubble:after {
    position: absolute;
    bottom: -32px;
    left: -2px;
    content: "";
    width: 9px;
    height: 9px;
    border: 4px solid #d0d0d0;
    background-color:#f0f0f0;
    border-radius:9px;
    z-index:1;
}

2016.7.12 改訂



関連記事


スポンサーリンク