CSS/CSS3

04 - CSS3知识点汇总二

2017-03-01  本文已影响41人  西巴撸

本文是针对刚学编程的小白,都是一些基础知识,如果想了解更多深层一点的东西,欢迎移步本人博客!!
博客地址 点击跳转

文章中我所提到的快捷键是用的webstrom编辑器,如果你用的不是webstrom的话,那你也改成webstorm吧,初学者还是用这款编辑器比较好


背景相关的所有属性

背景颜色

<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box4"></div>
    <style>
        div{
            width: 200px;
            height: 200px;
        }
        .box1{
            background-color: red;
        }
        .box2{
            background-color: rgb(0,255,0);
        }
        .box3{
            background-color: rgba(0,0,255,1);
        }
        .box4{
            background-color: #0ff;
            opacity: 0.5;
        }
    </style>

背景图片

1.图片地址必须放在url中 图片的地址可以是本地的 也可以是外部链接的
2.如果网页上出现了图片 浏览器会再次发送请求获取图片
3.如果图片没有指定的宽高那么大的话 那么他会自动拉伸平铺

<div class="box1"></div>
    <style>
        div{
            width: 400px;
            height: 400px;
        }
        .box1{
            background-image: url(images/girl.jpg);
            /*background-image: url(https://www.baidu.com/img/bd_logo1.png);*/

        }
    </style>

背景平铺

**1.repeat:默认 在水平和垂直都需要平铺
2.no-repeat:在水平和垂直都不需要平铺
3.repeat-x:水平平铺

4.repeat-y:垂直平铺**

<div class="box1"></div>
    <style>
        div{
            width: 500px;
            height: 500px;
        }
        .box1{
            background-image: url(images/girl.jpg);
            background-repeat: repeat-x;
        }
        body{
            background-image: url(images/bg2.jpg);
        }
    </style>

背景定位属性

具体的方位名称
1.水平方向:left center right
2.垂直方向:top bottom center

具体的像素
1.background-position: 100px 200px;
2.一定要记住写单位(px) 可以写负值

<div class="box1"></div>
    <style>
        div{
            width: 500px;
            height: 500px;
        }
        .box1{
            background-color: green;
            background-image: url(images/girl.jpg);
            background-repeat: no-repeat;
            background-position: center top;
            background-position: 100px 200px;
            background-position: -20px -50px;
        }
        body{
            background-repeat: no-repeat;
            background-image: url(images/yxlm.jpg);
            background-position: center 0;
        }
    </style>
背景定位属性

背景的缩写

    <style>
        div{

            width: 500px;
            height: 500px;
            background-color: green;
            background-image: url(images/girl.jpg);
            background-repeat: no-repeat;
            background-position: left bottom;
            background: green url(images/girl.jpg) no-repeat left bottom;
        }
        body{
            background-image: url(images/girl.jpg);
            background-repeat: no-repeat;
            background-attachment:fixed;
        }
    </style>

背景图片和插入图片区别

<div class="box1">我是文字</div>
<div class="box2">
    ![](images/girl.jpg)
    我是文字
</div>
    <style>
        div{
            /*width: 150px;*/
            /*height: 170px;*/
            width: 300px;
            height: 300px;
            background-color: red;
        }
        .box1{
            background-image: url(images/girl.jpg);
            background-repeat:no-repeat;
            background-position: right bottom;
        }
    </style>

CSS精灵图

CSS的精灵图是一种合成技术

CSS精灵图的作用

如果使用CSS精灵图

div class="box1"></div>
    <style>
        div{
            width: 86px;
            height: 28px;
            background-image: url(images/weibo.png);
            background-position: -425px -200px;
        }
    </style>
**精灵图**
精灵图

边框属性1

边框就是环绕在标签宽度和高度周围的线条

格式

1.连写格式中颜色可以省略 默认是黑色
2.连写格式中样式不可以省略 省略之后就看不到边框了
3.连写格式中宽度可以省略 省略之后还是可以看到
4.连写(分别设置四条边的边框)

**border-top:边框的宽度 边框的样式 边框的颜色;
border-bottom:边框的宽度 边框的样式 边框的颜色;
border-left:边框的宽度 边框的样式 边框的颜色;
border-right:边框的宽度 边框的样式 边框的颜色;
快捷键:
bt+
br+
bb+
bl+
**

<div class="box1"></div>
    <style>
        .box1{
            width: 200px;
            height: 200px;
            background-color:red;
            /*border: 5px solid blue;*/
            border-top: 5px solid yellow;
            border-right: 10px dashed green;
            border-bottom: 15px dotted purple;
            border-left: 20px double pink;
        }
    </style>
边框

边框属性2

连写(分别设置四条边的边框)

border-width: 上 右 下 左
border-style: 上 右 下 左
border-color: 上 右 下 左

**1.这三个属性的取值 是按照顺时针赋值的 也就是按照上右下左
2.这三个属性的取值 省略时的规律
2.1 上 右 下 左 > 上 右 下 > 左边的取值和右边的一样
2.2 上 右 下 左 > 上 右 > 左边的取值和右边的一样 下边的和上边的一样
2.3 上 右 下 左 > 上 > 右下左和上边的一样
**

非连写(方向+样式)

border-top-width:;
border-top-style:;
border-top-color: #000;
以此类推 ..

<div class="box"></div>
    <style>
        .box{
            width: 300px;
            height: 300px;
            background-color: red;
            /*border-width: 5px 10px 15px 20px;*/
            /*border-style:solid dashed dotted double;*/
            /*border-color: blue green purple pink;*/
            border-top-width:;
            border-top-style:;
            border-top-color: #000;
        }
    </style>

内边距属性

边框和内容之间的距离就是内边距

1.给标签设置内边之后 标签占有的原有宽度和高度会发生变化
2.给标签设置背景颜色 内边距也会有背景颜色

外边距属性

标签和标签之间的距离就是外边距

外边距的合并现象

<span class="hezi1">我是span</span><span class="hezi2">我是span</span>
<div class="box1"></div>
<div class="box2"></div>
    <style>
        span{
            display: inline-block;
            width: 100px;
            height: 100px;
            border: 1px solid black;
        }
        div{
            height: 100px;
            border: 1px solid #000;
        }
        .hezi1{
            margin-right: 50px;

        }
        .hezi2{
            margin-left: 100px;
        }
        .box1{
            margin-bottom:50px;

        }
        .box2{
            margin-top: 100px;
        }
    </style>

盒子模型

盒子只是一个形象的比喻 在HTML中所有的标签都是盒子

在HTML中所有的标签都可以设置
宽度/高度 == 指定可以存放内容区域
内边距 == 填充物
边框 == 手机盒子自己
外边距 == 盒子与盒子之间的间隙

<span>我是Span</span>
<a href="#">我是超链接</a>
<b>我是加粗</b>
<strong>我是强调</strong>
    <style>
        span,a,b,strong{
            display: inline-block;
            width: 100px;
            height: 100px;
            border: 5px solid #000;
            margin: 20px;
            padding: 20px;
        }
    </style>
盒子模型

盒子模型宽度和高度

内容的宽度和高度

通过标签的width和height属性设置的宽度和高度

元素的宽度和高度

宽度 = 左边的边框+内边距+内容的宽度+右边内边距+右边边框
高度 同理可证

元素空间的宽度和高度

宽度 = 左边的外边距+左边框+左内边距+内容的宽度

盒子的box-sizing属性

<div class="content">
    <div class="aside"></div>
    <div class="article"></div>
</div>
    <style>
        .content{
            width: 300px;
            height: 300px;
            background-color: red;
        }
        .aside{
            width: 100px;
            height: 200px;
            background-color: green;
            float: left;
        }
        .article{
            /*
            1.CSS3中新增了一个box-sizing属性 这个属性可以保证我们给盒子新增padding和border之后 盒子元素的自身宽度和高度不会发生改变
            2.box-sizing属性是如何保证盒子的padding和border之后.盒子元素的宽度和高度不变
            原理还是减去内容的宽度和高度
            3.box-sizing
            3.1 content-box
            元素的宽高 = 边框 + 内边距 + 内容宽高
            3.2 border-box
            元素的宽高 = width属性
            */
            box-sizing: border-box;
            width: 200px;
            height: 200px;
            background-color: blue;
            float: right;
            border: 20px solid #000;
            padding: 20px;
        }

    </style>

盒子居中和内容居中

<div class="father">
    我是文字<br>
    ![](images/girl.jpg)
    <div class="son"></div>
    <style>
        .father{
            width: 800px;
            height: 500px;
            background-color: green;
            text-align: center;
        }
        .son{
            width: 100px;
            height: 100px;
            background-color: blue;
            margin: 0 auto;
        }
    </style>
- #### 清空默认边距
        *{
            margin: 0;
            padding: 0;
        }
    <style>
        /*
        *{
            margin: 0;
            padding: 0;
        }
        */
        body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{
            margin: 0;
            padding: 0;
        }
        p{
            width: 610px;
            height: 110px;
            background-color: #cdcdcd;
            border: 1px solid #020202;
        }
    </style>
- #### 行高和字号
    <style>
        /*
        *{
            margin: 0;
            padding: 0;
        }
        */
        body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{
            margin: 0;
            padding: 0;
        }
        p{
            width: 610px;
            height: 110px;
            background-color: #cdcdcd;
            border: 1px solid #020202;
        }
        div{
            box-sizing: border-box;
            width: 100px;
            height: 80px;
            border: 1px solid #000;
            /*line-height: 80px;*/
            line-height: 20px;
            padding-top: 20px;
            padding-bottom: 20px;

        }
    </style>
- #### 还原字体和字号
    <style>
        body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{
            margin: 0;
            padding: 0;
        }
        p{
            box-sizing: border-box;
            width: 610px;
            height: 110px;
            background-color: #cdcdcd;
            border: 1px solid #020202;
            font-family:"黑体";
            font-size: 20px;
            line-height: 40px;
            color: #67676d;
            padding: 10px;
        }
    </style>
- #### 文章界面
<div>
    <h1>我是标题/<span>New Articles</span>></h1>
    <ul>
        <li>我是第一行,我是第一行</li>
        <li>我是第二行,我是第一行</li>
        <li>我是第三行,我是第一行</li>
        <li>我是第四行,我是第一行</li>
        <li>我是第五行,我是第一行</li>
    </ul>
</div>
    <style>
     body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{
            margin: 0;
            padding: 0;
        }
        body{
            background-color: #efefef;
        }
        div{
            box-sizing: border-box;
            width: 372px;
            height: 232px;
            border: 1px solid #666;
            margin: 0 auto;
            padding: 15px;
        }
        h1{
            font-family:"微软雅黑";
            font-size: 18px;
            border-bottom: 1px solid #666;
            padding-bottom:10px;
        }
        span{
            font-size: 14px;
        }
        ul{
            list-style:none;
            margin-top: 10px;
        }
        ul li{
            line-height:30px;
            border-bottom: 1px dashed #666;
            font-family:"微软雅黑";
            font-size:12px;
            color: #242424;
            padding-left:20px;
        }
    </style>
文章界面

- #### 网页布局方式

1.没有居中对齐 没有center取值
2.在浮动流中不可以使用margin:0 auto;的 是无效的
1.在浮动流中是不区分 块级标签/行内标签/行内块级标签 都可以水平排版
2.在浮动流中无论是块级标签/行内标签/行内块级标签都可以设置宽高
3.综上所述 浮动流中的元素和标准流中的行内块级元素很像\
<div class="box1"></div>
<div class="box2"></div>
    <style>
        .box1{
            width: 200px;
            height: 200px;
            background-color: red;
            display: inline-block;
            float: left;
        }
        .box2{
            width: 200px;
            height: 200px;
            background-color: blue;
            display: inline-block;
            float: right;
        }
    </style>
- #### 浮动元素的脱标
<div class="box1"></div>
<div class="box2"></div>
    <style>
        .box1{
            float: left;
            width: 100px;
            height: 100px;
            background-color: red;
        }
        .box2{
            width: 150px;
            height: 150px;
            background-color: blue;
        }
    </style>
脱标的盒子

- #### 浮动元素的排序规则

<div class="box1">1</div>
<div class="box2">2</div>
<div class="box3">3</div>
<div class="box4">4</div>
    <style>
        .box1{
            width: 50px;
            height: 50px;
            background-color: red;
            float: left;
        }
        .box2{
            /*float: left;*/
            width: 100px;
            height: 100px;
            background-color: pink;
        }
        .box3{
            float: left;
            width: 150px;
            height: 150px;
            background-color: yellow;
        }
        .box4{
            float: left;
            width: 200px;
            height: 200px;
            background-color: blue;
        }
    </style>
浮动的排序规则

- #### 浮动元素的贴靠现象

<div class="father">
    <div class="box1">1</div>
    <div class="box2">2</div>
    <div class="box3">3</div>
</div>
    <style>
        .father{
            width: 400px;
            height: 400px;
            border: 1px solid #000;
        }
        .box1{
             float: left;
             width: 50px;
             height: 300px;
             background-color: red;
         }
        .box2{
            float: left;
            width: 50px;
            height: 100px;
            background-color: green;
        }
        .box3{
            float: left;
            width: 250px;
            height: 100px;
            background-color: blue;
        }
    </style>
浮动元素的贴靠

- #### 浮动元素字围现象

![](images/picture.jpg)<p>养老金个账空账率超九成 将来兑现或入不敷出养老金个账空账率超九成 将来兑现或入不敷出养老金个账空账率超九成 将来兑现或入不敷出养老金个账空账率超九成 将来兑现或入不敷出养老金个账空账率超九成 将来兑现或入不敷出养老金个账空账率超九成 将来兑现或入不敷出养老金个账空账率超九成 将来兑现或入不敷出养老金个账空账率超九成 将来兑现或入不敷出养老金个账空账率超九成 将来兑现或入不敷出养老金个账空账率超九成 将来兑现或入不敷出养老金个账空账率超九成 将来兑现或入不敷出养老金个账空账率超九成 将来兑现或入不敷出养老金个账空账率超九成 将来兑现或入不敷出养老金个账空账率超九成 将来兑现或入不敷出养老金个账空账率超九成 将来兑现或入不敷出养老金个账空账率超九成 将来兑现或入不敷出养老金个账空账率超九成 将来兑现或入不敷出养老金个</p>
    <style>
        div{
            float: left;
            width: 100px;
            height: 100px;
            border: 1px solid #000;
            background-color: red;
        }
        p{
            width: 500px;
            height: 500px;
            background-color: pink;
        }
        img{
            float: left;
        }
    </style>
自围现象

- #### 浮动练习

<div class="header">
    <div class="logo"></div>
    <div class="language"></div>
    <div class="nav"></div>
</div>
<div class="content">
    <div class="aside"></div>
    <div class="article">
        <div class="articleTop">
            <div class="articleTopLeft">
                <div class="xinwen1"></div>
                <div class="xinwen2"></div>
            </div>
            <div class="articleTopRight"></div>
        </div>
        <div class="articleBottom"></div>
    </div>
</div>
<div class="footer"></div>
    <style>
        body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, code, del, dfn, em, img, q, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, dialog, figure, footer, header, hgroup, nav, section{
            margin: 0;
            padding: 0;
        }
        .header{
            width: 980px;
            height: 100px;
            margin: 0 auto;
        }
        .header .logo{
            float: left;
            width: 250px;
            height: 100px;
            background-color: pink;
        }
        .header .language{
            float: right;
            width: 150px;
            height: 50px;
            background-color: skyblue;
        }
        .header .nav{
            float: right;
            width: 650px;
            height: 50px;
            background-color: purple;
        }
        .content{
            width: 980px;
            height: 400px;
            margin: 0 auto;
            margin-top: 10px;
        }
        .content .aside{
            float: left;
            width: 320px;
            height: 400px;
            background-color: yellow;
        }
        .content .article{
            float: right;
            width: 650px;
            height: 400px;
        }
        .content .article .articleTop{
            width: 650px;
            height: 350px;
        }
        .content .article .articleTop .articleTopLeft{
            width: 400px;
            height: 350px;
            float: left;
        }
        .content .article .articleTop .articleTopLeft .xinwen1{
            width: 400px;
            height: 200px;
            background-color: deepskyblue;
        }
        .content .article .articleTop .articleTopLeft .xinwen2{
            width: 400px;
            height: 140px;
            background-color: deeppink;
            margin-top: 10px;
        }
        .content .article .articleTop .articleTopRight{
            width: 240px;
            height: 350px;
            background-color: blueviolet;
            float: right;
        }
        .content .article .articleBottom{
            width: 650px;
            height: 40px;
            background-color: brown;
            margin-top: 10px;
        }
        .footer{
            width: 980px;
            height: 40px;
            background-color: tomato;
            margin: 0 auto;
            margin-top: 10px;
        }
    </style>
浮动练习

书山有路勤为径 学海无涯苦作舟

更多精彩内容 请点击跳转

上一篇 下一篇

猜你喜欢

热点阅读