CSS3笔记

背景

背景大小控制(注意:大小要写在背景属性后面)

background-size:auto;/* 默认值,不改变背景图片的高度和宽度 */

background-size:100px 50px;/* 第一个值为宽,第二个值为高,当设置一个值时,将其作为图片宽度来等比缩放 */

background-size:10%;/* 0%~100%之间的任何值,将背景图片宽高按百分比显示,当设置一个值的时候同也将其作为图片宽度来等比缩放 */

background-size:cover;/* 将背景图片等比缩放填满整个容器 */

background-size:contain;/* 将背景图片等比缩放至某一边紧贴容器边缘 */


布局

【div自适应屏幕高度】

想要高度100%,需要在css里加写:html, body { height:100%}

这样设置的div高度才能达到100%

100%是相对的,想要铺满整个屏幕,一层层嵌套的div也得需要100%才行。


【div居中】

position:absolute;

top:50%; left:50%;

margin-top:-100px;(元素高度的一半)

margin-left:-100px;(元素宽度的一半)

【div宽度自适应内容】

width:fit-content;

width:-webkit-fit-content;

width:-moz-fit-content;


容器样式

【圆角】

border-radius:5px 5px 5px 5px;


动画

【平移动画】

@keyframes map_mc {

    0% {

        -webkit-transform: translate3d(0, 0, 0);

        transform: translate3d(0, 0, 0);

    }

    100% {

        -webkit-transform: translate3d(-200px, 0, 0);

        transform: translate3d(-200px, 0, 0);

        display: none;

    }

}

.map_mc{

background: url(img/map_mc.png) no-repeat;

    -webkit-animation: 10s map_mc linear infinite normal;

    animation: 10s map_mc linear infinite normal;

    position: relative;

}

写法2

CSS3的动画属性:

①.animation-name:

用于将动画(@keyframes 语法)附加到元素上;

②. animation-duration:

定义动画完成一次迭代(从0%到100%)所花的时间;

③. animation-timing-function:

类似于transition-timing-function属性,

用来更细粒度的控制动画的速度。

取值有: ease\ linear\ ease-in\ ease-out\ ease-in-out 之一

④.animation-iteration-count:

此属性用来定义动画要执行多少次。infinite无限次

⑤. animation-direction:

当动画迭代时,可以使用具有alternate的 animation- direction属性来使其他迭代反向播放动画。 默认normal;

⑥. animation-delay:

在开始执行动画时的延迟

⑦. animation-fill-mode:

取值有:none、forwards、backwards、both

定义在动画开始之前或者结束之后发生的动作

⑧. animation-play-state:

定义动画运行还是暂停

【摘自:CSDN博主「画一生情入颜容」的文章,原文链接:https://blog.csdn.net/csdn_zsdf/article/details/70807823 】

/*地球自转动画-start*/

.map_mc{

margin: 77px 0 0 0;

        position: absolute;

        width: 214px;

        height: 214px;

        background:url(img/map_mc.png) 156px top;

-webkit-mask: url(img/mc_zhezhao.png);

    -webkit-mask-size: cover;

        z-index:1;

        -webkit-animation-name: flymove;

        -webkit-animation-duration: 10s;

        -webkit-animation-timing-function: linear;

        -webkit-animation-iteration-count: 20000;

        -moz-animation-name: flymove;

        -moz-animation-duration: 10s;

        -moz-animation-timing-function: linear;

        -moz-animation-iteration-count: 20000;

        -ms-animation-name: flymove;

        -ms-animation-duration: 10s;

        -ms-animation-timing-function: linear;

        -ms-animation-iteration-count: 20000;

    }

    @-webkit-keyframes flymove{

            0%{background-position:0px 0px;}

            100%{background-position:370px 0;}

        }

        @-moz-keyframes flymove{

          0%{background-position:0px 0px;}

            100%{background-position:370px 0;}

        }

        @-ms-keyframes flymove{

          0%{background-position:0px 0px;}

            100%{background-position:370px 0;}

        }

/*地球动画-end*/

旋转动画

样式:

/*效果一:360°旋转 修改rotate(旋转度数)*/

       .mymc{

position: relative;

z-index: 100px;

width: 837px;

height: 837px;

margin: 0 auto 0 auto;

padding-top: 80px;

overflow: hidden;

}

.mydiv{

opacity: 0.3;

position: absolute;

z-index: 100px;

width: 837px;

height: 837px;

-webkit-transition-property: -webkit-transform;

    -webkit-transition-duration: 1s;

    -moz-transition-property: -moz-transform;

    -moz-transition-duration: 1s;

    -webkit-animation: rotate 50s linear infinite;

    -moz-animation: rotate 50s linear infinite;

    -o-animation: rotate 50s linear infinite;

    animation: rotate 50s linear infinite;

transform-origin: 50% 50% 0px;

        -webkit-transform-origin: 50% 50% 0px;

        -ms-transform-origin:  50% 50% 0px;

        -moz-transform-origin:  50% 50% 0px;

}

@-webkit-keyframes rotate{from{-webkit-transform: rotate(0deg)}

    to{-webkit-transform: rotate(360deg)}

}

@-moz-keyframes rotate{from{-moz-transform: rotate(0deg)}

    to{-moz-transform: rotate(359deg)}

}

@-o-keyframes rotate{from{-o-transform: rotate(0deg)}

    to{-o-transform: rotate(359deg)}

}

@keyframes rotate{from{transform: rotate(0deg)}

    to{transform: rotate(359deg)}

}

代码:

<div class="mymc">

<div class="mydiv"><img src="img/01.png" width="837" height="837" alt=""/></div>

<div class="breathe-div"></div>

</div>

一个CSS挺酷的呼吸圈

样式:

/*呼吸圈*/

.breathe-div {

    width: 500px;

    height: 500px;

    border: 1px solid #2b92d4;

    border-radius: 50%;

    text-align: center;

    cursor: pointer;

    margin:170px auto;

    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);

    overflow: hidden;

    -webkit-animation-timing-function: ease-in-out;

    -webkit-animation-name: breathe;

    -webkit-animation-duration: 1500ms;

    -webkit-animation-iteration-count: infinite;

    -webkit-animation-direction: alternate;

}

@-webkit-keyframes breathe {

    0% {

        opacity: .4;

        box-shadow: 0 1px 2px rgba(0, 147, 223, 0.4), 0 1px 1px rgba(0, 147, 223, 0.1) inset;

    }

    100% {

        opacity: 1;

        border: 1px solid rgba(59, 235, 235, 0.7);

        box-shadow: 0 1px 30px #0093df, 0 1px 20px #0093df inset;

    }

}


代码:

<div class="breathe-div"></div>

透明度

opacity:1.0;

纯 css写的图片轮播

/*图片轮播*/ .myad{ width: 750px; height: 422px; margin:255px 0 0 810px; position: absolute; background: url(img/yq_pic1.jpg) ; background-repeat: no-repeat; background-size:cover ; opacity: 1; animation: fateimg 10s linear infinite; } @keyframes fateimg{ 0%{background: url(img/yq_pic1.jpg);opacity: 1;background-repeat: no-repeat;background-size:cover ;} 30%{background: url(img/yq_pic1.jpg);opacity: 1;background-repeat: no-repeat;background-size:cover ;} 40%{background: url(img/yq_pic1.jpg);opacity: 0;background-repeat: no-repeat;background-size:cover ;} 50%{background: url(img/yq_pic2.jpg);opacity: 1;background-repeat: no-repeat;background-size:cover ;} 80%{background: url(img/yq_pic2.jpg);opacity: 1;background-repeat: no-repeat;background-size:cover ;} 90%{background: url(img/yq_pic2.jpg);opacity: 0;background-repeat: no-repeat;background-size:cover ;} 100%{background: url(img/yq_pic1.jpg);opacity: 1;background-repeat: no-repeat;background-size:cover ;} }

用CSS3实现鼠标移动到图片上图片变大效果

代码

div img:hover{

transition: all 0.6s;

transform: scale(1.4);

-webkit-transform: scale(1.4);

}

计算

calc()使用通用的数学运算规则,但是也提供更智能的功能:

使用“+”“-”“*”“/”四则运算;

可以使用百分比、px、em、rem等单位;

可以混合使用各种单位进行计算。

.box{

border:1px solid #ddd;

width:calc(100% - 100px);

background:#9AC8EB;

}

3栏等宽布局

.box{

margin-left:20px;

width:calc(100%/3 - 20px);

}

.box:nth-child(3n){

margin-left:0;

}


css 图片/视频的混合样式 mix-blend-mode

(不支持IE浏览器)

mix-blend-mode: normal;//正常

mix-blend-mode: multiply;//正片叠底

mix-blend-mode: screen;//滤色

mix-blend-mode: overlay;//叠加

mix-blend-mode: darken;//变暗

mix-blend-mode: lighten;//变亮

mix-blend-mode: color-dodge;//颜色减淡

mix-blend-mode: color-burn;//颜色加深

mix-blend-mode: hard-light;//强光

mix-blend-mode: soft-light;//柔光

mix-blend-mode: difference;//差值

mix-blend-mode: exclusion;//排除

mix-blend-mode: hue;//色相

mix-blend-mode: saturation;//饱和度

mix-blend-mode: color;//颜色

mix-blend-mode: luminosity;//亮度

mix-blend-mode: initial;//初始

mix-blend-mode: inherit;//继承

mix-blend-mode: unset;//复原

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 200,961评论 5 473
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 84,444评论 2 377
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 148,009评论 0 333
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,082评论 1 272
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,101评论 5 363
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,271评论 1 278
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,738评论 3 393
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,395评论 0 255
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,539评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,434评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,481评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,160评论 3 317
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,749评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,816评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,038评论 1 256
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,548评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,140评论 2 341

推荐阅读更多精彩内容

  • 选择qi:是表达式 标签选择器 类选择器 属性选择器 继承属性: color,font,text-align,li...
    love2013阅读 2,300评论 0 11
  • CSS 指层叠样式表(Cascading Style Sheets),是一种用来为结构化文档(如 HTML 文档或...
    神齐阅读 2,073评论 0 14
  • 软件DW编译代码的软件PS切图 修图浏览器chrome 谷歌firefox 火狐 FFIE 设计出设计图的前端还...
    蒲公英_前端开发者阅读 395评论 0 2
  • 一、CSS入门 1、css选择器 选择器的作用是“用于确定(选定)要进行样式设定的标签(元素)”。 有若干种形式的...
    宠辱不惊丶岁月静好阅读 1,579评论 0 6
  • background-image background-repeat background-position ba...
    MCM_Pan阅读 459评论 0 0