html div CSS 实现倒三角

<html>
    <head>
        <style>
            .boder {
               position:relative; 
               /*border:1px solid red;*/
                overflow:hidden;

            }
           span i {
              font-style:normal;  
              position:relative;
              top:-11px;  
              /*margin-top:-20px;*/
           
              /*border:1px solid red;*/
            }
            span {
                display:inline-block;
                 position:relative;
                 top:15px;
                  overflow:hidden;
                  /*border:1px solid black;*/
                  width:10px;

            }

            .bodercss i{
                        display:inline-block;
                    width: 0;
                    height: 0;
                    border-left: 5px solid transparent;
                    border-right: 5px solid transparent;
                    border-top: 10px solid red;
                    position:relative;
                    top:0px;
                       /*margin-top:-20px;*/
            }
        </style>    
    </head>

    <body>
        ddddd
        <!--特殊符号倒三角-->
        <div class="boder">test<span> <i>◆</i> </span></div>
        <!--边框倒三角-->
        <div class="bodercss">bordertest<i> </i></div>

    </body>
</html>

 如有任何疑问加技术Qun 594271193 交流 

使用CSS实现倒三角有多种方法: 1. **CSS边框法**:通过设置元素的宽度和高度为0,结合边框属性来实现。例如创建一个简单的倒三角,可使用如下代码: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> .h { width: 0px; height: 0px; border: 50px solid transparent; border-top-color: red; } </style> </head> <body> <div class="h"></div> </body> </html> ``` 若想改变三角方向,可将 `border-top-color` 改为 `border-left-color`、`border-right-color` 或者 `border-bottom-color`。若要调整形状,可随意调整边框的高度,如: ```css .h { width: 0; height: 0; border-left: 34px solid transparent; border-right: 40px solid transparent; border-top: 80px solid red; } ``` 使用这种方法,当需要实现其它方向的三角时,只需改变相应边框颜色属性即可;若要改变形状,可调整不同边框的宽度和高度 [^1]。 2. **旋转正方形法**:其主要原理是父元素将子元素不需要的部分超出隐藏,剩下倒三角形的形状。代码示例如下: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> .r { height: 14px; overflow: hidden; } .rr { position: relative; height: 20px; width: 12px; top: -12px; left: 7px; background: #0c0c0c; -moz-transform: rotate(45deg); -webkit-transform: rotate(45deg); -o-transform: rotate(45deg); transform: rotate(45deg); } </style> </head> <body> <div class="r"> <div class="rr"></div> </div> </body> </html> ``` 这种方法通过旋转子元素并利用父元素的溢出隐藏属性来形成倒三角 [^1]。 3. **特定样式设置法**:分别设置 `border-left` 和 `border-right` 为透明实线,将 `border-top` 设置为特定颜色的实线形成倒三角。代码如下: ```css .triangle { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 5px solid blue; } ``` 此方法通过精确设置边框属性来实现倒三角效果 [^2]。 4. **字符法**:利用一些三角形形状的字符的十进制 Unicode 表示码来实现倒三角。例如: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> .normal { font-size: 100px; color: skyblue; } </style> </head> <body> <div class="normal">▼</div> </body> </html> ``` 这里使用 `▼` 字符,并通过 CSS 设置其字体大小和颜色 [^3]。 5. **clip - path 法**:使用 `clip-path` 属性定义多边形来绘制倒三角。示例代码如下: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> .div { width: 100px; height: 87px; background: #c00; clip-path: polygon(0% 0%, 50% 100%, 100% 0%); } </style> </head> <body> <div class="div"></div> </body> </html> ``` 此方法通过 `clip-path` 的 `polygon` 函数来精确控制倒三角的形状 [^3]。 6. **设置边框和旋转法**:先设置边框形成三角,再通过旋转实现倒三角。代码如下: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> .uptriangle { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-bottom: 5px solid #fff; position: absolute; right: 37%; bottom: 19px; transform: rotate(180deg); } </style> </head> <body> <div class="uptriangle"></div> </body> </html> ``` 该方法先创建一个正三角,然后通过 `transform: rotate(180deg)` 旋转得到倒三角 [^5]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值