css5 给盒子加内描边怎么写

html-css011

css5 给盒子加内描边怎么写,第1张

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>

使用width来设置盒子内容区的宽度 使用height来设置盒子内容区的高度 width和height只是设置的盒子内容区的大小,而不是盒子的整个大小,盒子可见框的大小由内容区,内边距和边框共同决定为元素设置边框 要为一个元素设置边框必须指定三个样式border-width:边框的宽度border-color:边框颜色border-style:边框的样式使用border-width可以分别指定四个边框的宽度 如果在border-width指定了四个值 则四个值会分别设置给上、右、下、左,按照顺时针的方向设置的 如果指定三个值 则三个值会分别设置给上、左右、下 如果指定两个值 则两个值会分别设置给上下、左右 如果指定一个值,则四边全都是该值 除了border-width,CSS中还提供了四个border-xxx-width xxx的值可能是top right bottom left 专门用来设置指定边的宽度* 设置边框的颜色 * 和宽度一样,color也提供四个方向的样式,可以分别指定颜色 例如:border-color: red /*border-color: red yellow orange blue*/ /*border-color: red yellow orange*/ /*border-color: red yellow*/ 格式和边框设置颜色相同.* 设置边框的样式 * 可选值: * none,默认值,没有边框 * solid 实线 * dotted 点状边框 * dashed 虚线 * double 双线 * * style也可以分别指定四个边的边框样式,规则和width一致,同时它也提供border-xxx-style四个样式,来分别设置四个边设置边框 大部分的浏览器中,边框的宽度和颜色都是有默认值,而边框的样式默认值都是none */ /* border-width: 10px border-color: red border-style: solid*/ /* border - 边框的简写样式,通过它可以同时设置四个边框的样式,宽度,颜色 - 而且没有任何的顺序要求 - border一指定就是同时指定四个边不能分别指定 border-top border-right border-bottom border-left 可以单独设置四个边的样式,规则和border一样,只不过它只对一个边生效 */ /*border: red solid 10px*/ /*border-left: red solid 10px*/内边距: 内边距(padding),指的是盒子的内容区与盒子边框之间的距离,一共有四个方向: padding-top padding-right padding-bottom padding-left 内边距会影响盒子的可见框的大小,元素的背景会延伸到内边距 盒子的大小由内容区、内边距和边框共同决定 盒子可见框的宽度 = border-left-width + padding-left + width + padding-right + border-right-width 盒子可见框的高度 = border-top-width + padding-top + height + padding-bottom + border-bottom-width */ /*设置上内边距*/ /*padding-top: 100px*/ /*设置右内边距*/ /*padding-right: 100px padding-bottom: 100px padding-left: 100px*/ /* 使用padding可以同时设置四个边框的样式,规则和border-width一致 */ /*padding: 100px*/ /*padding: 100px 200px*/ /*padding: 100px 200px 300px*/外边距: 外边距指的是当前盒子与其他盒子之间的距离,他不会影响可见框的大小,而是会影响到盒子的位置 盒子有四个方向的外边距: margin-top margin-right margin-bottom margin-left 由于页面中的元素都是靠左靠上摆放的,所以注意当我们设置上和左外边距时,会导致盒子自身的位置发生改变,而如果是设置右和下外边距会改变其他盒子的位置 */ /*设置上外边距,即盒子的上边框与其他盒子的距离*/ /*margin-top: 100px*/ /*左外边距*/ /*margin-left: 100px*/ /*设置右和下外边距*/ /*margin-right: 100px margin-bottom: 100px*/ /* 外边距也可以指定为一个负值,如果外边距设置的是负值,则元素会向反方向移动 */ /*margin-left: -100px margin-top: -100px margin-bottom: -100px*/ /*margin-bottom: -100px*/ /* margin还可以设置为auto,auto一般只设置给水平方向的margin 如果只指定,左外边距或右外边距的margin为auto则会将外边距设置为最大值 垂直方向外边距如果设置为auto,则外边距默认就是0 如果将left和right同时设置为auto,则会将两侧的外边距设置为相同的值,就可以使元素自动在父元素中居中 所以我们经常将左右外边距设置为auto,以使子元素在父元素中水平居中 */ /*margin-left: auto margin-right: auto*/ /*margin-top: auto*/ /* 外边距同样可以使用简写属性 margin,可以同时设置四个方向的外边距,规则和padding一样 */ /*margin: 10px 20px 30px 40px*/ 为上边的元素设置一个下外边距:margin-bottom: 100px 为下边的元素设置一个上外边距:margin-top: 100px垂直外边距的重叠 在网页中相邻的垂直方向的外边距会发生外边距的重叠 所谓的外边距重叠指兄弟元素之间的相邻外边距会取最大值而不是取和 如果父子元素的垂直外边距相邻了,则子元素的外边距会设置给父元素.box3{ width: 200px height: 100px background-color: yellow /*为box3设置一个上边框*/ /*border-top: 1px red solid*/ /*padding-top: 1px*/ padding-top: 100px}.box4{ width: 100px height: 100px background-color: yellowgreen /*为子元素设置一个上外边距,使子元素的位置下移*/ /*margin-top: 100px*/浏览器为了在页面中没有样式时,也可以有一个比较好的显示效果,所以为很多的元素都设置了一些默认的margin和padding,而它的这些默认样式,正常情况下我们是不需要使用的。 所以我们往往在编写样式之前需要将浏览器中的默认的margin和padding统统的去掉 格式: *{ margin: 0 padding: 0}