美文网首页
day23 - css核心属性(总结)

day23 - css核心属性(总结)

作者: 未醒的梦_19b0 | 来源:发表于2018-12-05 19:02 被阅读0次

1.选择器优先级

选择器优先级
每种选择器都有一个权重值,权重值越大,优先级越高;权重值一样的时候谁后写,谁的优先级高
标签选择器:0001(1)
class选择器:0010(2)
id选择器: 0100(4)
群组选择器: 单独看每个选择器的权重
后代选择器: 每个单独的选择器的权重和
内联样式表的优先级永远最高

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            div #a1{
                color: yellow;
            }
            #div1 #div2 #a1{
                color: purple;
            }
            .ca1{
                color: green;
            }
            #a1{
                color: red;
            }
            a{
                color: blue;
            }
        </style>
    </head>
    <body>
        <div id="div1">
            <div id="div2">
                <a class="ca1" id="a1" href="" style="color: deeppink;">百度一下</a>
            </div>
        </div>
    </body>
</html>

2.标准流

css主要用来对网页中的内容进行布局和设置样式。
2.1.标准流: 网页中的内容在没有写样式的时候,默认的布局方式,我们就叫标准流
在标准流中不同类型的标签布局方式不一样:
a.如果是块级标签,一个标签占一行(无视宽度),默认的宽度就是父标签的宽度,默认高度是内容的高度,并且设置宽度和高度有效
b.如果是行内标签,一行可以显示多个,默认的宽度和高度都是内容的宽度和高度,设置宽度和高度无效
c.如果是行内块标签,一行可以显示多个,默认的宽度和高度都是内容的宽度和高度,设置宽度和高度有效
2.2.标签的默认分组
块级标签:h1~h6, p, table, ol, ul , dl, li, div....
行内标签: font, input, img, a, select, textarea, span....

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            
        </style>
    </head>
    <body>
        <!--练习:在使用<br/>的情况下,完成在网页上显示6个a标签,分两行显示,一行3个-->
        <div id="">
            <a href="">11</a>
            <a href="">22</a>
            <a href="">33</a>
        </div>
        <div id="">
            <a href="">44</a>
            <a href="">55</a>
            <a href="">66</a>
        </div>
    </body>
</html>

3.display属性

display属性值代表的是标签的类型:
3.1.block : 块标签
3.2.inline : 行内
3.3.inline-block : 行内块
默认情况下,我们的标签只有行内的和块的,没有行内块的。可以通过修改display属性值来修改标签类型
注意:使用行内块的时候,有一个没有办法修复的坑。行内块到其他标签之间有一个间隙,而且这个间隙不能消除。所以不到万不得已不使用行内块

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <!--1.块标签变成行内标签-->
        <p style="background-color: lightpink; display: inline; width: 200px;">我是段落</p>
        <p style="background-color: lightblue; display: inline;">我是段落2</p>
        <!--2.块标签变成行内块标签-->
        <p style="background-color: lightpink; display: inline-block; width: 200px;">我是段落3</p>
        <p style="background-color: lightblue; display: inline-block; height: 60px;">我是段落4</p>
        <!--3.行内转换成块-->
        <a href="", style="display: block;background-color: darkcyan;">a1</a>
        <a href="">a2</a>
    </body>
</html>

4.浮动

浮动(float):
letf: 左浮动 - 先上再左
right: 右浮动 - 先上再右
4.1.浮动会脱标(脱离标准流) - 之前标准流中的布局方式无效;
脱离标准流布局方式:所有标签都可以一行显示多个,默认大小是内容的大小,设置宽高有效
4.2.浮动
布局原则,努力的向浏览器的左上角靠,先上再左

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            p{
                float: left;
            }
            a{
                float: left;
            }
        </style>
    </head>
    <body>
        <!--1.脱标-->
        <!--<p style="background-color: chartreuse; width: 300px;">我是段落</p>
        <p style="background-color: salmon; width: 300px;">我是段落2</p>
        <a style="background-color: royalblue; width: 200px;">我是a标签</a>-->
        
        <!--2.浮动-->
        <!--<div style="background-color: seagreen; width: 200px; height: 100px; float: left;"></div>
        <div style="background-color: red; width: 300px; height: 120px;">
            
        </div>-->
        
        <!--3.左浮动-->
        <!--<div style="background-color: seagreen; width: 200px; height: 100px;"></div>
        <div style="background-color: red; width: 300px; height: 120px; float: left;">  
        </div>-->
        <!--<div style="width: 100px; height: 100px; background-color:red; float: left;">div1</div>
        <div style="width: 200px; height: 100px; background-color:green; float: left;">div1</div>
        <div style="width: 350px; height: 100px; background-color:blue;">div1</div>
        <div style="width: 400px; height: 100px; background-color:yellow; float: left;">div1</div>-->
        
        <!--4.右浮动-->
        <!--<div style="width: 200px; height: 100px; background-color:green; float: left;">div1</div>
        <div style="width: 350px; height: 100px; background-color:blue; float: right;">div1</div>-->
        
        <!--5.布局-->
        <div style="height: 150px; background-color: green;"></div>
        <div style="height: 300px; width: 50%; background-color: orange; float: left;"></div>
        <div style="width: 25%; height: 600px; background-color: deeppink; float: right;"></div>
        <div style="width: 25%; height: 600px; background-color: yellowgreen; float: right;"></div>
        <div style="width: 50%; height: 300px; background-color: slateblue; float: left;"></div>
    </body>
</html>

5.文字环绕

被文字环绕的标签浮动;文字对应的标签不浮动

6.清除浮动

6.1.高度塌陷
指的是清除因为浮动而产生的高度塌陷问题 - 父标签不浮动,子标签浮动就会产生高度塌陷问题
6.2.清除浮动
a.添加空盒子 - 在高度会塌陷的父标签中的最后添加一个空的div,并且设置这个空的div的样式的clear为both
b.overflow - 选中高度塌陷的标签,设置样式的overflow的值为hidden
c.万能清除法

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            /*清除浮动2*/
            /*#div1{
                overflow: hidden;
            }*/
            
            /*万能清除法*/
            #div1:after{
                display: block;
                content: "";
                visibility: hidden;
                clear: both;
                height: 0;
            }
            #div1{
                zoom: 1;
            }
        </style>
    </head>
    <body>
        <div style="height: 120px; background-color: brown;"></div>
        <div id="div1" style="background-color: seagreen;">
            <div style="height: 100px; width: 300px;background-color: sandybrown; float: left;"></div>
            <div style="height: 500px; width: 250px;background-color: skyblue; float: right;"></div>
            <!--清除浮动1-->
            <!--<div style="clear: both;"></div>-->
        </div>
        <div style="height: 120px; background-color: #9ACD32;"></div>
    </body>
</html>

7.定位

7.1.定位属性
letf - 标签的左边到指定位置的距离(左间距)
right - 标签的右边到指定位置的距离(右间距)
top - 标签的顶部到指定位置的距离(上间距)
bottom - 标签的底部到指定位置的距离(下间距)
7.2.position属性 - 设置标签定位的时候的参考对象(相对谁去定位)
initial/static(默认值) - 不相对任何对象定位
absolute(绝对定位) - 相对于第一个非initial/static的父标签进行定位
relative(相对定位) - 相对当前标签在标准流中的位置进行定位
(注意:一般把一个标签的position设置为relative是为了让当前标签的子标签可以相对自己定位)
fixed - 相对浏览器进行定位
sticky - 当网页中的内容超过一屏(需要滚动),相对浏览器定位;
当网页中的内容没有超过一屏(不需要滚动),相对标准流的位置进行定位;(注意:一般只针对最后一个标签)
注意:定位也会让标签脱标(脱流) - 不管怎么脱,标签都是按脱流的方式进行布局(一行显示多个,设置宽高有效,默认大小是内容大小)

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            /*absolute*/
            #div1{
                position: absolute;
                right: -30px;
                
            }
            #div2{
                position: relative;
                /*隐藏子标签超出的部分*/
                overflow: hidden;
            }
            
            span{
                position: absolute;
                left: 10px;
            }
        
        </style>
    </head>
    <body>
        <!--absolute-->
        <div style="width: 500px; height: 400px; background-color: darkorchid;" id="div3">
            <div style="width: 300px; height: 300px; background-color: yellowgreen;" id="div2">
                <div id="div1" style="width: 100px; height: 100px; background-color: hotpink;">
                </div>
                <span style="height: 60px; background-color: chocolate;">
                    横说竖说横说竖说
                </span>
            </div>
        </div>
        
        <!--relative-->
        <style type="text/css">
            #div5{
                position: relative;
                left: 100px;
                top: 100px;
            }
        </style>
        <div id="div4" style="width: 100px; height: 100px; background-color: sienna">
        </div>
        <div id="div5" style="width: 100px; height: 100px; background-color: sandybrown">
        </div>
        
        
        <!--3.fixed-->
        <style type="text/css">
            #div6{
                position: fixed;
                right: 0px;
                bottom: 0px;
            }
        </style>
        <div id="div6" style="width: 150px; height: 80px; background-color: skyblue">
            <a href="">回到顶部</a>
        </div>
        
        <!--4.sticky-->
        <style type="text/css">
            #div7{
                position: sticky;
                bottom: 0px;
            }
        </style>
        <div id="div7" style="width: 100%; height: 60px; background-color: darkkhaki">
            
        </div>
    </body>
</html>

8.盒子模型

html中所有在网页上可见的标签都是盒子模型,有固定的结构.
所有可见的标签都是由:content、padding、border和margin组成,其中内容、padding、border是可见的,margin不可见
8.1.content - a.设置width和height就是在设置content的大小;
b.标签中添加内容也是添加到content中的
c.设置背景颜色,会作用于content
8.2.padding - a.通过padding相关属性设置padding的大小(4个方向)
b.设置背景颜色,会作用于padding
8.3.border(边框) - a.通过border相关属性设置border的大小(4个方向)
b.边框的颜色需要单独设置
4.margin - a.通过margin相关属性设置margin的大小
b.不可见,但是占位

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <style type="text/css">
            div{
                /*1.设置content的大小*/
                width: 100px;
                height: 100px;
                background-color: sandybrown;
                
                /*2.设置padding大小*/
                /*a.同时给4个边添加padding*/
                /*padding: 20px;*/ 
                
                /*b.分别给不同的边添加padding*/
                padding-left: 20px;
                padding-top: 30px;
                
                /*3.border*/
                /*a.同时给4个边添加border
                 * border: 宽度 样式 颜色
                 * 样式 - solid(实线)/dashed(虚线)/dotted(点划线)/double(双线)
                 */
                /*border: 6px dashed slateblue;*/
                
                /*b.单独设不同边的边框*/
                border-left: 3px solid darkblue;
                border-top: 3px dashed yellowgreen;
                
                /*4.margin*/
                /*margin: 100px;*/
                margin-left: 50px;
            }
        </style>
        <div id="">
            <a href="">python</a>
        </div>
        
        姓名:<input type="text" name="" id="" value="" style="padding-left: 20px;"/>
    </body>
</html>

相关文章

  • day23 - css核心属性(总结)

    1.选择器优先级 选择器优先级每种选择器都有一个权重值,权重值越大,优先级越高;权重值一样的时候谁后写,谁的优先级...

  • day23 css核心属性

    1选择器的优先级 每种选择器都有一个权重值,权重值越大,优先级越高;权重值一样的时候谁后写,谁的优先级高标签选择器...

  • 2018-09-19 css核心属性

    DAY4:CSS核心属性 学习目标 1、css浮动属性详解 2、css文本属性 3、css列表属性 4、css背景...

  • HTMLCSS学习笔记(四)-- CSS属性

    CSS属性 属性:属性是指定选择符所具有的属性,它是css的核心,css2共有150多个属性属性值:属性值包括法定...

  • 过渡、动画、转换(2D/3D)、渐变

    零:总结 手动触发-->改变属性 + transition属性说明=css过渡css写好触发->改变属性+ a...

  • CSS核心属性

    第一节 文本类型属性 font-family:字体类型 语法:{font-family:字体1,字体2,字体3;}...

  • css核心属性

    一、字体类属性 1.字体类型 语法: font-family:字体1,字体2,字体3; eg: body{font...

  • css核心属性

    标准流 display属性 float属性 文字环绕:被环绕的标签浮动没蚊子不浮动 清除浮动 定位 盒子模型

  • CSS核心属性

    1.选择器优先级 每种选择器都有一个权重值,权重值越大,优先级越高标签选择器:0001(1)class选择器:00...

  • day23 CSS属性

    01选择器的权重 选择器的权重类型选择器(元素选择器):0001class选择器:0010id选择器:0100层级...

网友评论

      本文标题:day23 - css核心属性(总结)

      本文链接:https://www.haomeiwen.com/subject/uimwcqtx.html