CSS能在页面画一条斜线吗

html-css011

CSS能在页面画一条斜线吗,第1张

能,一种是使用css样式:先画一条横线或竖线,然后将这条线旋转一定角度得到斜线。代码如下:

<style>

#book{width:300pxheight:20pxborder-bottom:1px solid #000000-webkit-transform: rotate(45deg)/*Safari 4+,Google Chrome 1+ */-moz-transform: rotate(45deg)/*Firefox 3.5+*/filter: progid:DXImageTransform.Microsoft.BasicImage(Rotation=0.45)}</style><div id="book"></div>

另外一种需要使用canvas标签,通过js实现:先画一块画板,再通过两点定位直接在画板上画线。代码如下:

<canvas id="myline" style="width:500pxheight:500px">

</canvas>

<script>

var c=document.getElementById("myline")

var ctx=c.getContext("2d")

ctx.beginPath()

ctx.moveTo(0,0)

ctx.lineTo(300,150)

ctx.stroke()

</script>

<div class="radian"></div>

.radian{

width: 200px

height: 100px

border-radius: 200px/20px/*上下有弧度的边*/

/*border-radius: 20px/200px*//*左右有弧度的边*/

background-color: red

}

border-radius是一种缩写方法。如果“/”前后的值都存在,那么“/”前面的值设置其水平半径,“/”后面值设置其垂直半径。

HTML

<ul>

    <li class="cur">全民设计师</li>

    <li>全民设计师</li>

    <li>全民设计师</li>

    <li>全民设计师</li>

    <li>全民设计师</li>

</ul>

CSS

ul {

    display: block

    margin: 0

    padding: 0

    font-size: 0

}

li {

    display: inline-block

    position: relative

    padding-top: 15px

    width: 20%

    font-size: 14px

    text-align: center

}

li:before {

    display: block

    position: absolute

    left: 0

    right: 0

    top: 5px

    height: 2px

    content: ""

    background-color: #000

}

li:after {

    display: block

    position: absolute

    left: 0

    right: 0

    top: 0

    margin: 0 auto

    border-radius: 100%

    border: 1px solid #000

    width: 10px

    height: 10px

    content: ""

    background-color: #000

}

li:first-child:before {

    left: 50%

}

li:last-child:before {

    right: 50%

}

li.cur:after {

    background-color: #fff

}

在线演示:

http://jsfiddle.net/geLrep8n/