这个CSS怎么写?带斜边

html-css07

这个CSS怎么写?带斜边,第1张

代码如下:

html:

<div id="div3">

<div class="arrow-top"></div>

</div>

css:

#div3 {

position: relative

width: 300px

height: 200px

background-color: yellow

}

.arrow-top {

position: absolute

top: -50px

left: -50px /*移动距离为小三角的宽高*/

width: 0px

height: 0px

border-width: 50px /*小三角的高度*/

border-style: solid

border-color: transparent transparent #C73837 transparent /*朝上的小三角*/

transform: rotate(-45deg) /*将小三角旋转到你想要的角度*/

}

你可以根据自己的需要进行微调

1、理论

三角形实现原理:宽度width为0;height为0;

(1)有一条横竖边(上下左右)的设置为border-方向:长度 solid red,这个画的就是底部的直线。其他边使用border-方向:长度 solid transparent。

(2)有两个横竖边(上下左右)的设置,若斜边是在三角形的右边,这时候设置top或bottom的直线,和右边的斜线。若斜边是在三角形的左边,这时候设置top或bottom的直线,和左边的斜线。

二、实现

2.1 Triangle Up

#triangle-up {width:0    height:0    

border-left:50px solid transparent    

border-right:50px solid transparent    

border-bottom:100px solid red}

2.2 Triangle Down

#triangle-down {width:0    height:0  

  border-left:50px solid transparent    

border-right:50px solid transparent    

border-top:100px solid red}

2.3 Triangle Left

#triangle-left {

width:0  

  height:0  

  border-top:50px solid transparent  

  border-right:100px solid red   

 border-bottom:50px solid transparent}

2.4 Triangle Right

#triangle-right {width:0    

height:0    

border-top:50px solid transparent   

 border-left:100px solid red    

border-bottom:50px solid transparent}

2.5 Triangle Top Left

#triangle-topleft {width:0  

  height:0    

border-top:100px solid red   

 border-right:100px solid transparent}

2.6 Triangle Top Right

#triangle-topright {width:0   

 height:0  

  border-top:100px solid red    

border-left:100px solid transparent}

2.7 Triangle Bottom Left

#triangle-bottomleft {width:0   

 height:0    

border-bottom:100px solid red   

 border-right:100px solid transparent}

2.8 Triangle Bottom Right

#triangle-bottomright {width:0    

height:0   

 border-bottom:100px solid red    

border-left:100px solid transparent}

DIV里没有和PS一样的斜切。可以先把矩形CTRL+Q转曲。然后按F10对每个节点进行调整。

DIV在编程中又叫做整除,即只得商的整数。 DIV元素是用来为HTML文档内大块(block-level)的内容提供结构和背景的元素。DIV的起始标签和结束标签之间的所有内容都是用来构成这个块的,其中所包含元素的特性由DIV标签的属性来控制,或者是通过使用样式表格式化这个块来进行控制。