[摘要]本篇文章给大家带来的内容是关于如何用css实现直接画出三角形以及对话形式的三角形(附代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。在商品展示中,画三角形的出现的也挺多的,左上...
本篇文章给大家带来的内容是关于如何用css实现直接画出三角形以及对话形式的三角形(附代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
在商品展示中,画三角形的出现的也挺多的,左上角的三角标签,又或者对话形式的三角形,带阴影效果等,在此记录下
1、直接添加三角形
<div class="triangleContainer">
    <div class="triangleContent">
        <div class="triangle"></div>
        <div class="title">想你呦</div>
    </div>
</div>
<style>
    body {
        background: #e5e5e5;
    }
    .triangleContainer {
        margin: 50px auto;
        width: 500px;
        height: 400px;
        background: #fff;
    }
    .triangleContent {
        position: relative;
    }
    .triangle {
        position: absolute;
        right: -70px;
        top: -70px;
        transform: rotate(45deg);
        /* 比较长的写法 */
        /*border-top: 70px solid transparent;*/
        /*border-bottom: 70px solid red;*/
        /*border-left: 70px solid transparent;*/
        /*border-right: 70px solid transparent;*/
        /* 简单写法 */
        border: 70px solid transparent;
        border-bottom-color: red;
    }
    .title {
        position: absolute;
        right: 8px;
        top: 17px;
        transform: rotate(45deg);
        font-size: 19px;
        color: #fff;
    }
</style>