CSS如何定义一条水平虚线?

html-css021

CSS如何定义一条水平虚线?,第1张

需要准备的材料分别有:电脑、浏览器、html编辑器。

1、首先,打开html编辑器,新建html文件,例如:index.html。

2、在index.html中的<style>标签中,输入css代码:div {height:60pxborder-bottom:1px dashed}。

3、浏览器运行index.html页面,此时通过css定义了一个水平的虚线。

能,一种是使用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>

要在文字中间实现有一条横线的效果可以使用CSS中CSS text-decoration 属性就可以达到效果。

CSS text-decoration 属性相关介绍及事例:

浏览器支持:所有主流浏览器都支持 text-decoration 属性。

定义、用法和说明:text-decoration 属性规定添加到文本的修饰。

CSS text-decoration 属性的值:

A、none    默认。定义标准的文本。

B、underline    定义文本下的一条线。

C、overline    定义文本上的一条线。

D、line-through    定义穿过文本下的一条线。

E、blink    定义闪烁的文本。

F、inherit    规定应该从父元素继承 text-decoration 属性的值。

实例:

h1 {text-decoration:overline}

h2 {text-decoration:line-through}

h3 {text-decoration:underline}

h4 {text-decoration:blink}

设置 h1、h2、h3、h4 元素的文本修饰。

注释:

A、任何的版本的 Internet Explorer (包括 IE8)都不支持属性值 "inherit"。

B、IE、Chrome 或 Safari 不支持 "blink" 属性值。

C、修饰的颜色由 "color" 属性设置。

D、这个属性允许对文本设置某种效果,如加下划线。如果后代元素没有自己的装饰,祖先元素上设置的装饰会“延伸”到后代元素中。不要求用户代理支持 blink。