css border:transparent

1.border属性transparent

默认值。边框颜色为透明。可以借此属性画一些基本形状,典型就是三角形

c2969260005e81584a9fe5ad46438f7.png
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        body {
            padding: 0;
            margin: 0;
        }

        .css-cell {
            position: relative;
            width: 100%;
            height: 300px;
        }

        .bubbly {
            width: 0;
            height: 0;
            border-top: 40px solid transparent;
            border-left: 40px solid #ff0000;
            border-bottom: 40px solid transparent;
        }
    </style>
</head>

<body>
    <div class="css-cell">
        <div class="bubbly"></div>
    </div>
</body>

</html>

所以,如果我们要做倒立三角形、向右的、或者向左的三角形,只需要为三角形底部设置边框,两腰边框透明即可

2.和伪类结合
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        body {
            padding: 0;
            margin: 0;
        }

        .css-cell {
            position: relative;
            width: 100%;
            height: 300px;
        }

        .bubbly {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background: #00ccbb;
            border-radius: 8px;
            width: 200px;
            padding: 40px 10px;
            text-align: center;
            color: white;
            font-size: 20px;
        }

        .bubbly:after {
            content: '';
            position: absolute;
            bottom: -34px;
            left: 50%;
            border: 34px solid transparent;
            border-top-color: #00ccbb;
            border-bottom: 0;
            border-left: 0;

        }
    </style>
</head>

<body>
    <div class="css-cell">
        <div class="bubbly"></div>
    </div>
</body>

</html>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 各种纯css图标 CSS3可以实现很多漂亮的图形,我收集了32种图形,在下面列出。直接用CSS3画出这些图形,要比...
    剑残阅读 9,766评论 0 8
  • 一、CSS入门 1、css选择器 选择器的作用是“用于确定(选定)要进行样式设定的标签(元素)”。 有若干种形式的...
    宠辱不惊丶岁月静好阅读 1,665评论 0 6
  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5? 答:HTML5是最新的HTML标准。 注意:讲述HT...
    kismetajun阅读 27,908评论 1 45
  • 1、属性选择器:id选择器 # 通过id 来选择类名选择器 . 通过类名来选择属性选择器 ...
    Yuann阅读 1,680评论 0 7
  • 原创/ 喵星电影 小动物 “三个智猴”的典故,源于佛教训诫—— 一个双手捂眼做惨不忍睹状(see no evil)...
    喵星电影阅读 1,083评论 0 0