css3一些新增属性介绍
导读
css3和css有什么区别?简单来讲css3是css(层叠样式表)技术的升级版本,css3新特征有很多,例如圆角效果、图形化边界、块阴影与文字阴影、使用RGBA实现透明效果、渐变效果、使用@Font-Face实现定制字体、多背景图、文字或图像的变形处理(旋转、缩放、倾斜、移动)、多栏布局、媒体查询等。
边框border-radius
:边框圆角,值为圆的直径;
border-image
:url('') x y round/repeat/stretch 实现边框图片环绕/平铺/拉伸,注意设置border:30px solid transparent;
背景图background-size
的比例乘容器设置盒子大小为背景图大小,通过background-origin
调整背景图大小和位置;阴影通过box-shadow
:x偏移 y偏移 阴影模糊值 阴影外延值 阴影的颜色 内阴影;
文本阴影通过text-shadow
: x y 偏移 颜色;
如何实现自定义字体?
通过@font-face提前将字体引入,有效避免用户电脑因为没有这款字体而文字变形;
word-break: break-all
;与word-wrap: break-word
的区别在于,前者是单词折行,
下面是代码展示部分:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>css3新增边框、阴影、背景、文本、字体</title> <style type="text/css"> /*border-radius:边框圆角 圆角直径*/ div#ceshi{ width: 200px; height: 200px; background-color: #f90; margin-bottom: 50px; /* border-radius: 50%; border-radius: 200px; */ border-radius: 1px 10px 30px 70px;/*顺时针*/ border-radius: 1px 10px 30px;/*对角线*/ border-radius: 1px 10px; border-radius: 10px; } /*#ceshi{ box-shadow: 10px 20px 30px 10px purple inset; }*//*X偏移 Y偏移 阴影模糊值 阴影往外延伸 阴影颜色 内阴影*/ #ceshi{ box-shadow: 10px 20px 30px 10px red; } /* border-image:url('') X y round/repeat/stretch 边框图片环绕/平铺/拉伸 */ div.box{ width: 128px; height: 128px; background-color: #ccc; margin: 0 auto; border:30px solid transparent; /* border-image:url('images/b.png') 20 20 round; */ border-image-source:url('images/b.png'); border-image-slice: 20; border-image-width: 10; border-image-outset:1; border-image-repeat:round; margin-bottom: 100px; } /*背景样式background-size*//*background-origin背景图大小和位置*/ .pic{ width: 400px; height: 300px; border: 10px solid red; background: url(https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy /it/u=1314383665,2282288429&fm=11&gp=0.jpg) no-repeat; background-size: 50%;/*容器宽度乘百分比为背景图大小*/ background-origin: border-box;/*边框区域*/ background-origin: padding-box;/*内边框区域*/ background-origin: content-box;/*有效区域*/ } /*文本字体*/ .text{ text-shadow: 5px 1px 2px red;/*文本阴影*/ width: 400px; border: 1px inset green; margin-top: 50px; word-break: break-all;/*单词折行*/ word-wrap: break-word; font-family: dhnblog; } /*自定义字体类型*/ @font-face{ font-family:dhnblog; src:url('images/fzm.ttf'); } </style> <script> window.onload=function(){ var obj=document.getElementById('ceshi') obj.onclick=function(){ console.log('音乐不能阻碍工作,是为了更好的服务工作') } } </script> </head> <body> <div id="ceshi"></div> <div> <img src="images/ft.png" alt=""> </div> <div> 今日の天気は良い今日の天気は良い今日の天気は良い今日の天気は良い </div> <div> <p>Once the sea was difficult for the waterExcept Wushan is not a cloudYou are to me the sea and Wushan </p> <p>海が水にとって困難だったら武山は雲ではないこ とを除いてあなたは私にとって海と武山です</p> <p>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p> <p>Maybe program apes are not good at words, and warmth is hidden in the cold and the heat inside, but those seemingly cold codes can also be combined into the most romantic and beautiful love words. Today we take a look at how programmers put love words into romance. Code.</p> </div> </body> </html>
评论(0)