CSS3入门
CSS3
CSS3 is the latest evolution of the Cascading Style Sheets language and aims at extending CSS2.1. It brings a lot of long-awaited novelties(备受期待的新特性), like rounded corners, shadows, gradients, transitions or animations, as well as new layouts like multi-columns, flexible box or grid layouts.(圆角,阴影,渐变,渐变,过渡,动画和新的布局多栏,弹性盒子,网格布局)
Experimental parts are vendor-prefixed and should either be avoided in production environments, or used with extreme caution as both their syntax and semantics can change in the future.
CSS3 Modules
CSS3 has been split into "modules".(这些模块彼此独立, 按照各自的进度来进行标准化) It contains the "old CSS specification" (which has been split into smaller pieces). In addition, new modules are added.
Some of the most important CSS3 modules are:
- Selectors
- Box Model
- Backgrounds and Borders
- Image Values and Replaced Content
- Text Effects
- 2D/3D Transformations
- Animations
- Multiple Column Layout
- User Interface
Most of the new CSS3 properties are implemented in modern browsers.
一些新增的CSS3属性
border-radius
IE9+
border-image
<'border-image-source'> || <'border-image-slice'> [ / <'border-image-width'> | / <'border-image-width'>? / <'border-image-outset'> ]? || <'border-image-repeat'>
CSS3 Backgrounds
background-image
给同一个元素增加多个背景图片
CSS3 allows you to add multiple background images for an element
background-size
The CSS3 background-size
property allows you to specify the size of background images.
Before CSS3, the size of a background image was the actual size of the image. CSS3 allows us to re-use background images in different contexts.
The size can be specified in 1: lengths, 2: percentages, or by using one of the 3: two keywords: contain or cover.
stretch: 把图片宽高都让其与容器适应
cover 某一边适应容器,而另一边被切割
contain 看电影一样会留下黑边
background-origin
The CSS3 background-origin
property specifies where the background image is positioned.
The property takes three different values:
- border-box - the background image starts from the upper left corner of the border
- padding-box - (default) the background image starts from the upper left corner of the padding edge
- content-box - the background image starts from the upper left corner of the content
background-clip
The CSS3 background-clip
property specifies the painting area of the background.
The property takes three different values:
- border-box - (default) the background is painted to the outside edge of the border
- padding-box - the background is painted to the outside edge of the padding
- content-box - the background is painted within the content box
CSS3 Colors
CSS supports color names, hexadecimal and RGB colors.
In addition, CSS3 also introduces:
- RGBA colors #p1 {background-color: rgba(255, 0, 0, 0.3);}
- HSL colors #p1 {background-color: hsl(120, 100%, 50%);}
- HSLA colors #p1 {background-color: hsla(120, 100%, 50%, 0.3);}
- opacity #p1 {background-color:rgb(255,0,0);opacity:0.6;}
CSS3 Gradients(IE10+)
CSS3 gradients let you display smooth transitions between two or more specified colors.
Earlier, you had to use images for these effects. However, by using CSS3 gradients you can reduce download time and bandwidth usage. In addition, elements with gradients look better when zoomed, because the gradient is generated by the browser.
CSS3 Shadow Effects
With CSS3 you can add shadow to text and to elements.
In this chapter you will learn about the following properties:
text-shadow
box-shadow
text-shadow(IE10+)
The CSS3 text-shadow
property applies shadow to text.
In its simplest use, you only specify the horizontal shadow (2px) and the vertical shadow (2px):
box-shadow(IE9+)
The CSS3 box-shadow
property applies shadow to elements.
CSS3 Text
CSS3 contains several new text features.
In this chapter you will learn about the following text properties:
text-overflow
word-wrap
word-break
text-overflow
The CSS3 text-overflow
property specifies how overflowed content that is not displayed should be signaled to the user.
text-overflow: clip ellipsis "string"
word-wrap
允许长单词换行到下一行. 允许长单词被拦腰打断转换到另一行
word-break
The word-break
CSS property is used to specify whether to break lines within words.
word-break: normal;
word-break: break-all;
word-break: keep-all;
Web Fonts
CSS3 Web Fonts(在线字体) - The @font-face Rule
Web fonts allow Web designers to use fonts that are not installed(没有安装在用户计算机上的) on the user's computer.
When you have found/bought the font you wish to use, just include the font file on your web server, and it will be automatically downloaded to the user when needed.
Different Font Formats
TTF OTF WOFF WOFF2.O SVG Fonts/Shape EOT
SVG Fonts/Shape:SVG fonts allow SVG to be used as glyphs when displaying text.
例子:
@font-face {
font-family: myFirstFont;
src: url(sansation_light.woff);
}
div {
font-family: myFirstFont;
}
CSS3 Transforms
CSS3 transforms allow you to translate, rotate, scale, and skew(移动,旋转,缩放,拉伸) elements.
A transformation is an effect that lets an element change shape, size and position(形状,大小,位置).
CSS3 supports 2D and 3D transformations.
2D Transforms(IE10+)
translate()
rotate()
scale()
skewX()
skewY()
matrix()
2D Transform Methods
Function | Description |
---|---|
matrix(n,n,n,n,n,n) | Defines a 2D transformation, using a matrix of six values |
translate(x,y) | Defines a 2D translation, moving the element along the X- and the Y-axis |
translateX(n) | Defines a 2D translation, moving the element along the X-axis |
translateY(n) | Defines a 2D translation, moving the element along the Y-axis |
scale(x,y) | Defines a 2D scale transformation, changing the elements width and height |
scaleX(n) | Defines a 2D scale transformation, changing the element's width |
scaleY(n) | Defines a 2D scale transformation, changing the element's height |
rotate(angle) | Defines a 2D rotation, the angle is specified in the parameter |
skew(x-angle,y-angle) | Defines a 2D skew transformation along the X- and the Y-axis |
skewX(angle) | Defines a 2D skew transformation along the X-axis |
skewY(angle) | Defines a 2D skew transformation along the Y-axis |
transform:translate()
The translate()
method moves an element from its current position (according to the parameters given for the X-axis and the Y-axis).
transform:rotate()
2D 的旋转
The rotate()
method rotates an element clockwise or counter-clockwise(逆时针) according to a given degree.
transform:scale()
The scale()
method increases or decreases the size of an element (according to the parameters given for the width and height).
transform:skewX()
The skewX()
method skews an element along the X-axis by the given angle.
transform:skewY()
The skewY()
method skews an element along the Y-axis by the given angle.
transform:skew()
The skew()
method skews an element along the X and Y-axis by the given angles.
transform: matrix()
The matrix()
method combines all the 2D transform methods into one.
The matrix() method take six parameters, containing mathematic functions, which allows you to rotate, scale, move (translate), and skew elements.
The parameters are as follow: matrix(scaleX(),skewY(),skewX(),scaleY(),translateX(),translateY()):
transform-origin
Allows you to change the position(位置) on transformed elements
CSS3 3D Transforms
CSS3 allows you to format your elements using 3D transformations.
CSS3 Transform Properties
The following table lists all the 3D transform properties:
Property | Description |
---|---|
transform | Applies a 2D or 3D transformation to an element |
transform-origin | Allows you to change the position on transformed elements |
transform-style | Specifies how nested elements are rendered in 3D space |
perspective | Specifies the perspective on how 3D elements are viewed |
perspective-origin | Specifies the bottom position of 3D elements |
backface-visibility | Defines whether or not an element should be visible when not facing the screen |
transform-style
transform-style: flat|preserve-3d|initial|inherit;
perserve-3d Specifies that child elements will preserve its 3D position
3D Transform Methods
Function | Description |
---|---|
matrix3d (n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n) |
Defines a 3D transformation, using a 4x4 matrix of 16 values |
translate3d(x,y,z) | Defines a 3D translation |
translateX(x) | Defines a 3D translation, using only the value for the X-axis |
translateY(y) | Defines a 3D translation, using only the value for the Y-axis |
translateZ(z) | Defines a 3D translation, using only the value for the Z-axis |
scale3d(x,y,z) | Defines a 3D scale transformation |
scaleX(x) | Defines a 3D scale transformation by giving a value for the X-axis |
scaleY(y) | Defines a 3D scale transformation by giving a value for the Y-axis |
scaleZ(z) | Defines a 3D scale transformation by giving a value for the Z-axis |
rotate3d(x,y,z,angle) | Defines a 3D rotation |
rotateX(angle) | Defines a 3D rotation along the X-axis |
rotateY(angle) | Defines a 3D rotation along the Y-axis |
rotateZ(angle) | Defines a 3D rotation along the Z-axis |
perspective(n) | Defines a perspective view for a 3D transformed element |
rotateX(),rotateY(),rotateZ()
3D旋转,围绕空间的3D坐标
perspective
好吧,CSS3 3D transform变换,不过如此! 原理演示网站
Set the perspective(视点) from where an element is viewed
Transitions(过渡效果IE10+)
CSS3 transitions allows you to change property values smoothly (from one value to another), over a given duration.
transition | A shorthand property for setting the four transition properties into a single property |
transition-delay | Specifies a delay (in seconds) for the transition effect |
transition-duration | Specifies how many seconds or milliseconds a transition effect takes to complete |
transition-property | Specifies the name of the CSS property the transition effect is for |
transition-timing-function | Specifies the speed curve of the transition effect |
transition: property duration timing-function delay;
Animations(动画)
CSS3 animations allows animation of most HTML elements without using JavaScript or Flash!
What are CSS3 Animations?
An animation lets an element gradually change from one style to another.
You can change as many CSS properties you want, as many times you want.
To use CSS3 animation, you must first specify some keyframes for the animation.
Keyframes hold what styles the element will have at certain times.
The following table lists the @keyframes rule and all the animation properties:
Property | Description |
---|---|
@keyframes | Specifies the animation code |
animation | A shorthand property for setting all the animation properties |
animation-delay | Specifies a delay(延迟) for the start of an animation |
animation-direction | Specifies whether an animation should play in reverse direction or alternate cycles |
animation-duration | Specifies how many seconds or milliseconds an animation takes to complete one cycle |
animation-fill-mode | Specifies a style for the element when the animation is not playing (when it is finished, or when it has a delay) |
animation-iteration-count | Specifies the number of times an animation should be played |
animation-name | Specifies the name of the @keyframes animation |
animation-play-state | Specifies whether the animation is running or paused |
animation-timing-function | Specifies the speed curve of the animation |
animation: name duration timing-function delay iteration-count direction;
animation-direction: normal|alternate;
animation-direction 属性定义是否应该轮流反向播放动画。
CSS Images
Rounded Images
Use the border-radius
property to create rounded images:
Thumbnail Images
Use the border
property to create thumbnail images.
Responsive Images(响应式)
Responsive images will automatically adjust(自动调整) to fit the size of the screen.
Center an Image
To center an image within the page, use margin: auto;
and make it into a block element:
img {
display: block;
margin: auto;
width: 50%;
}
Image Filters
The CSS filter
property adds visual effects (like blur and saturation) to an element.
Note: The filter property is not supported in Internet Explorer(IE不支持), Edge 12, or Safari 5.1 and earlier.
CSS Buttons
CSS Pagination Examples
CSS3 Multi-column Layout
The CSS3 multi-column layout allows easy definition of multiple columns of text - just like in newspapers(像报纸文字那样的多栏布局):
In this chapter you will learn about the following multi-column properties:
column-count
column-gap
column-rule-style
column-rule-width
column-rule-color
column-rule
column-span
column-width
column-count
The column-count
property specifies the number of columns an element(元素被分为多少列) should be divided into.
column-gap
分栏之间的间距
Column Rules
column-rule column-rule-width column-rule-style column-rule-color
分栏之间的宽度 样式 颜色
column-span
元素“横跨”多少栏
column-width
栏目宽度
User Interface
resize
whether or not an element should be resizable by the user.
outline-offset
adds space between an outline and the edge or border of an element.(外边框和边距之间的距离)
Box-sizing
content-box(default),border-box,padding-box
区别在于计算宽度高度时的差别
Flexbox
new layout mode in CSS3
Media Queries
CSS3入门的更多相关文章
- Web大前端时代之:HTML5+CSS3入门系列
准备来一波新技术,待续.... Old: 联系源码:https://github.com/dunitian/LoTHTML5 文档下载:https://github.com/dunitian/LoTD ...
- 07. Web大前端时代之:HTML5+CSS3入门系列~H5 地理位置
Web大前端时代之:HTML5+CSS3入门系列:http://www.cnblogs.com/dunitian/p/5121725.html 源码:https://github.com/duniti ...
- 01.Web大前端时代之:HTML5+CSS3入门系列~初识HTML5
Web大前端时代之:HTML5+CSS3入门系列:http://www.cnblogs.com/dunitian/p/5121725.html 文档申明 <!--文档类型申明,html代表是ht ...
- 02.Web大前端时代之:HTML5+CSS3入门系列~H5结构元素
Web大前端时代之:HTML5+CSS3入门系列:http://www.cnblogs.com/dunitian/p/5121725.html 1.结构元素 可以理解为语义话标记,比如:以前这么写&l ...
- 03.Web大前端时代之:HTML5+CSS3入门系列~H5功能元素
Web大前端时代之:HTML5+CSS3入门系列:http://www.cnblogs.com/dunitian/p/5121725.html 2.功能元素 1.hgroup 对网页或区段(secti ...
- 04. Web大前端时代之:HTML5+CSS3入门系列~HTML5 表单
Web大前端时代之:HTML5+CSS3入门系列:http://www.cnblogs.com/dunitian/p/5121725.html 一.input新增类型: 1.tel:输入类型用于应该包 ...
- 05. Web大前端时代之:HTML5+CSS3入门系列~H5 多媒体系
Web大前端时代之:HTML5+CSS3入门系列:http://www.cnblogs.com/dunitian/p/5121725.html 1.引入 概述 音频文件或视频文件都可以看做是一个容器文 ...
- 06. Web大前端时代之:HTML5+CSS3入门系列~HTML5 画布
Web大前端时代之:HTML5+CSS3入门系列:http://www.cnblogs.com/dunitian/p/5121725.html 我们先看看画布的魅力: 初始画布 canvas默认是宽3 ...
- 08. Web大前端时代之:HTML5+CSS3入门系列~H5 Web存储
Web大前端时代之:HTML5+CSS3入门系列:http://www.cnblogs.com/dunitian/p/5121725.html
- 08. Web大前端时代之:HTML5+CSS3入门系列 ~ QQ空间时间轴
Web大前端时代之:HTML5+CSS3入门系列:http://www.cnblogs.com/dunitian/p/5121725.html 大前端系列,主要就是使用CSS3.0来实现,注释我已经打 ...
随机推荐
- Ruby设计模式透析之 —— 组合(Composite)
转载请注明出处:http://blog.csdn.net/sinyu890807/article/details/9153761 此为Java设计模式透析的拷贝版,专门为Ruby爱好者提供的,不熟悉R ...
- Linux 内核源码中likely()和unlikely()
ikely()与unlikely()在2.6内核中,随处可见,那为什么要用它们?它们之间有什么区别呢? 首先明确: if (likely(value))等价于if (value)if (likely( ...
- Java项目中打开本地文件的方法
1:其中saveAddress 为已知本地文件全路径: Desktop.getDesktop().open(new File(saveAddress));
- 利用fiddler将本地网页放到某个域下
注: 1)在学习慕课网课程<搜索框制作>中遇到如题困难,查找资料后解决,做此记录.课程网址http://www.imooc.com/video/263. 2)建议同时去学习慕课网课程< ...
- CodeForces 213B Numbers
$dp$,组合数. $dp[i][j]$表示只用数字$i$,$i+1$,$i+2$......,$9$,凑成长度为$j$的并且数字$i$到$9$符合要求的方案数.只要枚举数字$i$用几个就可以转移了. ...
- 2017年IT互联网圈跑会指南~
啦啦啦~要放假啦,还有十多天就要过年啦,要走亲访友啦!相信大家也是各种胡吃海喝后,啊咧~腰上好像多了好几圈o(>﹏<)o为了让小伙伴们及时制定年后行程(减膘)计划,活动家特此奉上2017年 ...
- Android进程回收的一些知识
关于OOM_ADJ说明: Android 进程易被杀死的情形: 参考:Android进程保活招式大全
- 在Windows上创建同样的Linux操作环境
在之前的文章中,介绍了我在GNU/Linux图形界面环境下所使用的工具集合.其基本目的是在保证占用最少系统资源的条件下,将电脑操作效率推向极致.这样的工具组合尤如瑞士军刀一般,简洁.高效.功能全面.与 ...
- python3 数据类型
Python3 中有六个标准的数据类型: Number(数字) String(字符串) List(列表) Tuple(元组) Sets(集合) Dictionary(字典) Number(数字) Py ...
- 冰刃IceSword中文版 V1.22 绿色汉化修正版
软件名称: 冰刃IceSword中文版 V1.22 绿色汉化修正版 软件语言: 简体中文 授权方式: 免费软件 运行环境: Win 32位/64位 软件大小: 2.1MB 图片预览: 软件简介: Ic ...