CSS3入门

时间:2022-12-29 00:28:01

CSS3

w3cschools css3  MDN英文  MDN中文

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入门的更多相关文章

  1. Web大前端时代之:HTML5&plus;CSS3入门系列

    准备来一波新技术,待续.... Old: 联系源码:https://github.com/dunitian/LoTHTML5 文档下载:https://github.com/dunitian/LoTD ...

  2. 07&period; Web大前端时代之:HTML5&plus;CSS3入门系列~H5 地理位置

    Web大前端时代之:HTML5+CSS3入门系列:http://www.cnblogs.com/dunitian/p/5121725.html 源码:https://github.com/duniti ...

  3. 01&period;Web大前端时代之:HTML5&plus;CSS3入门系列~初识HTML5

    Web大前端时代之:HTML5+CSS3入门系列:http://www.cnblogs.com/dunitian/p/5121725.html 文档申明 <!--文档类型申明,html代表是ht ...

  4. 02&period;Web大前端时代之:HTML5&plus;CSS3入门系列~H5结构元素

    Web大前端时代之:HTML5+CSS3入门系列:http://www.cnblogs.com/dunitian/p/5121725.html 1.结构元素 可以理解为语义话标记,比如:以前这么写&l ...

  5. 03&period;Web大前端时代之:HTML5&plus;CSS3入门系列~H5功能元素

    Web大前端时代之:HTML5+CSS3入门系列:http://www.cnblogs.com/dunitian/p/5121725.html 2.功能元素 1.hgroup 对网页或区段(secti ...

  6. 04&period; Web大前端时代之:HTML5&plus;CSS3入门系列~HTML5 表单

    Web大前端时代之:HTML5+CSS3入门系列:http://www.cnblogs.com/dunitian/p/5121725.html 一.input新增类型: 1.tel:输入类型用于应该包 ...

  7. 05&period; Web大前端时代之:HTML5&plus;CSS3入门系列~H5 多媒体系

    Web大前端时代之:HTML5+CSS3入门系列:http://www.cnblogs.com/dunitian/p/5121725.html 1.引入 概述 音频文件或视频文件都可以看做是一个容器文 ...

  8. 06&period; Web大前端时代之:HTML5&plus;CSS3入门系列~HTML5 画布

    Web大前端时代之:HTML5+CSS3入门系列:http://www.cnblogs.com/dunitian/p/5121725.html 我们先看看画布的魅力: 初始画布 canvas默认是宽3 ...

  9. 08&period; Web大前端时代之:HTML5&plus;CSS3入门系列~H5 Web存储

    Web大前端时代之:HTML5+CSS3入门系列:http://www.cnblogs.com/dunitian/p/5121725.html  

  10. 08&period; Web大前端时代之:HTML5&plus;CSS3入门系列 ~ QQ空间时间轴

    Web大前端时代之:HTML5+CSS3入门系列:http://www.cnblogs.com/dunitian/p/5121725.html 大前端系列,主要就是使用CSS3.0来实现,注释我已经打 ...

随机推荐

  1. &lbrack;LeetCode&rsqb; Product of Array Except Self 除本身之外的数组之积

    Given an array of n integers where n > 1, nums, return an array output such that output[i] is equ ...

  2. html&amp&semi;css中的文字对齐问题

    html&css的使用过程中,我们经常会遇到很多文字对齐问题.下面我要介绍一个有丁点难的文字对齐问题. 实现效果如下图所示.   两行长度不定的文字,要让它们总体水平居中,然后,这两行字要左对 ...

  3. SWOT自我分析

    个人信息: 大三学生 二本大学 软件工程专业 一:SWOT自我分析 Strenghs(优势): 1.有着良好的作息习惯,坚持锻炼 2.专注力强,能沉下心来学习 3.有着强烈的危机意思,明白不仅则退的道 ...

  4. debugging python with IDLE

    1. start IDLE "Python 2.5"→"IDLE(Python GUI)" 2. open your source file window Fr ...

  5. mov sreg&comma; r&sol;m16 在16位和32位编程中的区别

    总结于<X86汇编语言 从实模式到保护模式> 仅适用于X86系列处理器 1. 两者的区别: 例:mov ds, ax A.在指定16位编译模式下,产生的二进制码是 8E D8 B.在指定3 ...

  6. SQL慢查询测试实践

    1.开启慢查询的目的 开启慢查询日志,可以让MySQL记录下查询超过指定时间的语句,通过定位分析性能的瓶颈,才能更好的优化数据库系统的性能. 2.设置mysql慢查询 方法一:全局变量设置(临时生效) ...

  7. Java学习笔记之——常用转义符号

    \ 单独用会报错 \\   打印右斜杠 \n   换行 \t   Tab键 \"   双引号 \'   单引号

  8. HTML的基本知识点

    <!DOCTYPE HTML> <html> <body> <video width="320" height="240&quo ...

  9. mac电脑安装selenium 记录

    1.使用终端去命令安装 sudo easy_install selenium 参考:https://www.cnblogs.com/nichoc/p/5543654.html 2.听说驱动放在 /us ...

  10. IntelliJ IDEA 配置JSP &amp&semi; Servlet开发环境

    首先我们要安装和配置好JAVA和TOMCAT,这里不再详细描述 下载地址: JAVA:https://www.oracle.com/technetwork/java/javase/downloads/ ...