用CSS创造三角形案例

6.3.2 用CSS创造三角形

用div来创建,角上是平分的,所以要是内部宽高为0,其他边透明,正好是三角形。

代码

css 复制代码
div {
    border: 12px solid;
    width: 0;
    height: 0;
    border-color: transparent red transparent transparent;
}

与伪元素after结合起来,在6.3.弹出层.html中增加CSS:

css 复制代码
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <style>
        figure {
            width: 144px;
            height: 153px;
            margin: 20px 20px;
            border: 1px solid #666;
            position: relative;
            float: left;
        }

        img {
            width: 144px;
            height: 153px;
            display: block;
        }

        figcaption {
            display: none;
            /* 隐藏弹出层 */
            position: absolute;
            /* 相对于容器 */
            left: 74%;
            /* 放到右边 */
            top: 15px;
            width: 130px;
            /* 弹出层宽度 */
            padding: 10px;
            /* 弹出层内边距 */
            background-color: #f2eaea;
            border: 3px solid red;
            border-radius: 6px;
        }

        /* 鼠标悬停在图片上显示 */
        figure:hover figcaption {
            display: block;
        }

        figcaption h3 {
            /*弹出层的内容*/
            font-size: 14px;
            color: #666;
            margin-bottom: 6px;
        }

        figcaption a {
            /*弹出层的内容*/
            display: block;
            text-decoration: none;
            font-size: 12px;
            color: #000;
        }

        /* 把弹出层设置为最高层 */
        figure:hover figcaption {
            display: block;
            z-index: 2;
        }

        /* 红色三角形盒子 */
        figcaption::after {
            content: "";
            position: absolute;
            border: 12px solid;
            border-color: transparent red transparent transparent;
            height: 0px;
            width: 0px;
            top: 17px;
            right: 100%;
        }
    </style>
</head>

<body>
    <figure>
        <img src="img/pink.jpg" alt="pink heels" />
        <figcaption>
            <h3>Pink Platforms</h3>
            <a href="#">More info</a>
        </figcaption>
    </figure>
    <figure class="click_me">
        <img src="img/baowen.jpg" alt="baowen heels" />
        <figcaption>
            <h3>Leopard Platforms</h3>
            <a href="#">More info</a>
        </figcaption>
    </figure>
    <figure class="click_me">
        <img src="img/red.jpg" alt="red heels" />
        <figcaption>
            <h3>Red Platforms</h3>
            <a href="#">More info</a>
        </figcaption>
    </figure>
</body>

</html>
相关推荐
jnene4 小时前
html 时间、价格筛选样式处理
前端·css·html
用户059540174468 小时前
Redis 缓存过期不一致踩坑实录:一个 bug 让我排查了 3 小时,最终用 Pytest 自动化堵上漏洞
前端·css
神明不懂浪漫8 小时前
【第三章】CSS(一)——基础选择器、CSS的属性
前端·css·html·css3
用户059540174468 小时前
localStorage清除策略踩坑实录:一个过期的token让我排查了3小时
前端·css
#麻辣小龙虾#10 小时前
js实现视频播放画中画模式
javascript·css·音视频
低保和光头哪个先来11 小时前
聊聊 CSS 编译和 scoped 实现
前端·css·vue.js
在逃花果山的小松1 天前
CSS 调试头大报错难查?ChatGPT 一键定位样式问题并给出修复方案
css
编程技术手记1 天前
Vue Scoped CSS 与动态创建 DOM 的兼容性问题
前端·css·vue.js
用户059540174461 天前
LangChain 记忆模块踩坑实录:靠自动化测试,我把上下文丢失率从 30% 降到 0
前端·css
雨翼轻尘1 天前
03_HTML进阶标签与CSS入门
前端·css·html·入门·进阶标签