<div id="nav">
布局
</div>
</body>
CSS代码: #nav{border: solid #000000 3px} 黑色外边框,宽度为3px;
可以看出fillText实心文字先绘制,strokeText空心文字后绘制,他们坐标一致,所以直接覆盖可实心文字,形成了像文字内部描边通过text-shadow添加文字阴影可以形成对文字的外描边
注释:Internet Explorer 9 以及更早版本的浏览器不支持 text-shadow 属性。
可以看下这个文章,关于text-shadow
https://www.cnblogs.com/wuchuanlong/p/5985350.html
css5 是何方神圣?
css div描边
border: 1px red solid
有很多参数,自己百度:css border 和 css outline
CSS3文字描边
text-shadow:#000 1px 0 0,#000 0 1px 0,#000 -1px 0 0,#000 0 -1px 0-webkit-text-shadow:#000 1px 0 0,#000 0 1px 0,#000 -1px 0 0,#000 0 -1px 0
-moz-text-shadow:#000 1px 0 0,#000 0 1px 0,#000 -1px 0 0,#000 0 -1px 0
*filter: Glow(color=#000, strength=1)
html5描边
HTML5 Canvas 填充与描边(Fill And Stroke)
<!DOCTYPE html><html>
<head>
<meta http-equiv="X-UA-Compatible" content="chrome=IE8">
<meta http-equiv="Content-type" content="text/htmlcharset=UTF-8">
<title>Canvas Fill And Stroke Text Demo</title>
<link href="default.css" rel="stylesheet" />
<script>
var ctx = null // global variable 2d context
var imageTexture = null
window.onload = function() {
var canvas = document.getElementById("text_canvas")
console.log(canvas.parentNode.clientWidth)
canvas.width = canvas.parentNode.clientWidth
canvas.height = canvas.parentNode.clientHeight
if (!canvas.getContext) {
console.log("Canvas not supported. Please install a HTML5 compatible browser.")
return
}
// get 2D context of canvas and draw rectangel
ctx = canvas.getContext("2d")
ctx.fillStyle="black"
ctx.fillRect(0, 0, canvas.width, canvas.height)
// fill and stroke text
ctx.font = '60pt Calibri'
ctx.lineWidth = 3
ctx.strokeStyle = 'green'
ctx.strokeText('Hello World!', 20, 100)
ctx.fillStyle = 'red'
ctx.fillText('Hello World!', 20, 100)
// fill and stroke by pattern
imageTexture = document.createElement('img')
imageTexture.src = "../pattern.png"
imageTexture.onload = loaded()
}
function loaded() {
// delay to image loaded
setTimeout(textureFill, 1000/30)
}
function textureFill() {
// var woodfill = ctx.createPattern(imageTexture, "repeat-x")
// var woodfill = ctx.createPattern(imageTexture, "repeat-y")
// var woodfill = ctx.createPattern(imageTexture, "no-repeat")
var woodfill = ctx.createPattern(imageTexture, "repeat")
ctx.strokeStyle = woodfill
ctx.strokeText('Hello World!', 20, 200)
// fill rectangle
ctx.fillStyle = woodfill
ctx.fillRect(60, 240, 260, 440)
}
</script>
</head>
<body>
<h1>HTML5 Canvas Text Demo - By Gloomy Fish</h1>
<pre>Fill And Stroke</pre>
<div id="my_painter">
<canvas id="text_canvas"></canvas>
</div>
</body>
</html>