首页 > 其他分享 >【CSS】画三角形

【CSS】画三角形

时间:2023-09-05 21:12:18浏览次数:36  
标签:solid top 50px 三角形 border transparent CSS

<html>
    <head>
        <title>CSS 绘制三角形</title>
    </head>
    <body>
        <div>
            <h1>实心三角形</h1>
            <div class="filled-triangle-1"></div>
            
            <div>
                <h1>等边三角形</h1>
                <div class="filled-triangle-2"></div>
            </div>

            <h1>聊天气泡</h1>
            <div class="chat-triangle">yo, bro!</div>
        </div>
    </body>

    <style>
        .filled-triangle-1 {
            width: 0;
            height: 0;
            border: 50px solid red;
            border-bottom: 50px solid cyan;
            border-right: 50px solid yellow;
            border-top: 50px solid green;
        }

        /* 等边三角形 */
        .filled-triangle-2 {
            width: 0;
            height: 0;
            border-left: 50px solid transparent; /* transparent 表示透明 */
            border-right: 50px solid transparent;
            border-bottom: 87px solid #ff0000; 
        }

        .chat-triangle {
            position: relative;
            width: 300px; 
            height: 60px; 
            padding: 10px;
            border: 1px solid cyan; 
            border-radius: 8px;
        }
        /* 深色三角形 */
        .chat-triangle::before {
            position: absolute;
            top: 34px; 
            left: -10px; 
            border-top: 6px solid transparent; 
            border-bottom: 6px solid transparent; 
            border-right: 10px solid cyan;
            content: '';  
        }
        /* 画一个白色的三角形盖上去,错位 2 个像素 */
        .chat-triangle::after{
            position: absolute; 
            top: 34px; 
            left: -8px; 
            border-top: 6px solid transparent; 
            border-bottom: 6px solid transparent; 
            border-right: 10px solid #fff;
            content: '';  
        }
    </style>
</html>

 

标签:solid,top,50px,三角形,border,transparent,CSS
From: https://www.cnblogs.com/zjy4fun/p/17680802.html

相关文章

  • 【CSS】伪类选择器和伪元素选择器
    伪类选择器用于指定所选元素的特殊状态,参考https://developer.mozilla.org/zh-CN/docs/Web/CSS/Pseudo-classes伪元素选择器允许你对被选择元素的特定部分修改样式,不会真的修改dom结构,参考https://developer.mozilla.org/zh-CN/docs/Web/CSS/Pseudo-elements<html><head>......
  • 如何在Nuxt 3中为<html>和<body>标签添加Tailwind CSS类?
    在Nuxt3中为<html>和<body>标签添加TailwindCSS类,可以参考以下步骤:安装TailwindCSS:在项目根目录下运行以下命令安装TailwindCSS和其依赖:npminstalltailwindcss@latest@tailwindcss/typography@latestpostcss@latestautoprefixer@latest创建TailwindCSS配置......
  • 记录--CSS 滚动驱动动画 scroll()
    这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助CSS滚动驱动动画scroll()animation-timeline通过scroll()指定可滚动元素与滚动轴来为容器动画提供一个匿名的scrollprogresstimeline.通过元素在顶部和底部(或左边和右边)的滚动推进scrollprogresst......
  • 【css兼容】flex在低版本 chrome 浏览器的兼容问题
    https://blog.csdn.net/weixin_43841308/article/details/111246537 前言【感官】使用ElementUI构建如下布局【逻辑】具体代码:【现象】谷歌浏览器44.0.2403.125m版本显示main内容不全谷歌浏览器57.0.2987.133版本页面正常flex兼容性【猜想】display:flex在网站兼容性......
  • css设置滚动条样式
    首先给父盒子设置overflow:hidden;overflow-y:scroll;overflow-x:scroll;这样子盒子超出父级的高度和宽度时就会出现滚动条接着调整滚动条样式/*里面的代码可以根据自己需求去进行更改*//*设置滚动条的样式*/::-webkit-scrollbar{width:12px;}/*滚动槽*/......
  • [译]这几个CSS小技巧,你知道吗?
    前言在网页设计和前端开发中,CSS属性是非常重要的一部分。掌握常用的CSS属性不仅可以使你的网页看起来更美观,还能提升用户体验,今天小编为大家介绍8个常见的CSS小技巧:1.修改滚动条样式下图是我们常见的滚动条,现在需要改变滚动条的宽度和颜色了,并把它画的圆一点。(常见的滚动条)......
  • CSS如何让鼠标放上时的小手样式
     cursor:pointer;参考:https://www.muzhuangnet.com/show/56515.html......
  • css学习
    字体:1、样式继承:例如font-size2、字体风格:font-style是否倾斜3、字体粗细:font-weight4、字之间的间隔:letter-spacing5、首行缩进:text-indent6、水平居中:text-align7、行高:line-heigh8、vertical-align:操作行内元素 ......
  • html+css应用一
    css:层叠级联样式表CSS的三种引入方式1.行内样式:写在标记里面的,只对当前的文件起作用,复用性小。2.内部样式:写在文件内部的,只对当前文件的文件中指定的标记有作用,复用性大于行内样式。3.外部样式:把样式单独抽离出来到一个css文件中,并引入。复用性大于内部样式。例:html文件:<!DOCTYPE......
  • css: SVG and CSS
    https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/SVG_and_CSS两种方式的CSS  SVGCSS:/***SVGdemonstration***//*page*/svg{background-color:beige;}#heading{font-size:24px;font-weight:bold;}#caption{font-size:12px;}......