HTML & CSS

CSS实现对话框小三角效果

2017-08-08  本文已影响0人  JeremyChi

效果图

应用场景

一般在模拟对话框类UI时使用

实现思路

代码

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Test Page</title>
    <link rel="stylesheet" href="style/main.css">
    <style>
        .dialog{
            width: 200px;
            height: 100px;
            border: 1px solid #ccc;
            margin :  50px auto;
            position: relative;
        }
        .triangle:before{
            content: '';
            border-right: 20px solid #ccc;
            border-top: 20px solid transparent;
            border-bottom: 20px solid transparent;
            border-left: 0;
            position: absolute;
            left: 0;
            top: 50%;
            margin-left: -20px;
            margin-top: -20px;
        }
        .triangle:after{
            content: '';
            border-right: 20px solid #fff;
            border-top: 20px solid transparent;
            border-bottom: 20px solid transparent;
            border-left: 0;
            position: absolute;
            left: 0;
            top: 50%;
            margin-left: -19px;
            margin-top: -20px;
        }
    </style>
</head>

<body>
    <div class="dialog triangle">Let's party!</div>
</body>

</html>
上一篇下一篇

猜你喜欢

热点阅读