【实习第八天】浮动

1.浮动的简介

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box{
            width: 500px;
            height: 600px;
            background-color: #fff;
            /* margin: 0 auto; */
            /* float: left; */
        }

        /* .box{
            width: 100px;
            height: 100px;
            background-color: red;
            float: left;
        } */

        .box1{
            width: 100px;
            height: 100px;
            background-color: green;
            /* float: left; */
        }

        .box2{
            width: 100px;
            height: 100px;
            background-color: orange;
            /* float: left; */
        }

        .box3{
            width: 100px;
            height: 100px;
            background-color: red;
            /* float: left; */
        }


    </style>
    <!-- 
        浮动(float)
        浮动是一种布局手段,会使元素脱离文档流
        元素在文档流的时候,会分块元素,行内元素。行内块元素,各自都有一定的特点

        设置元素浮动,可以用float样式
            可选值:
                none    默认值,不浮动
                left    向左浮动
                right   向右浮动

        设置浮动后的一些特点:(第一类特点)
            1、设置元素浮动后,元素会脱离文档流,就不会再占据原来在文档流的位置,设置浮动元素后面的元素就会向上
            2、设置元素浮动后,元素会尽可能向左或者向右浮动,浮动元素不会超过前一个兄弟
            3、如果浮动元素前一个兄弟没有浮动,浮动的元素不会跑上去
     -->
</head>
<body>
    <div id="box">
        <div class="box1" class="box"></div>
        <div class="box2" class="box"></div>
        <div class="box3" class="box"></div>
    </div>
</body>
</html>

2.浮动特点2

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box{
            width: 400px;
            height: 400px;
            background-color: #bfa;
            margin: 50px auto;
        }

        .box1{
            width: 100px;
            height: 100px;
            background-color: red;
            float: left;

        }
        /* 浮动的第二类特点
        当浮动的元素碰到了文字,浮动的元素不会盖住文字,文字会环绕在浮动元素的周围
        这也是浮动元素最初的特点
        
        */
    </style>
    
</head>
<body>
    <div id="box">
        <div class="box1"></div>
        <p class="box2">判她可拆鼓李种,后下化未远越冇范,不手订火王最国自破对即行尝六志越,畴张动终此我后,亓关在衣感极,小张此起见性不平失回冈活韩,沉设先而洪仇宫,次冷谓司大李争答变上问他前主有,德动无斯才,甲不且,备我。</p>
    </div>
</body>
</html>

3.浮动特点3

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box1{
            width: 100px;
            height: 100px;
            background-color: red;
        }
        .s1{
            width: 100px;
            height: 100px;
            background-color:pink;
            float: left;
        }

        .box2{
            width: 100px;
            height: 100px;
            background-color: green;
            float: left;
        }

    
    </style>
    <!-- 
        浮动元素的第三类特点
        设置元素浮动后,元素脱离文档流,元素原来在文档流中分类,特点就不复存在
        也就是说行内元素可以设置宽高了,块元素也不会独占一行了,行内块元素也没有三像素的问题了
     -->
</head>
<body>
    <div class="box1">我是box1</div>
    <span class="s1">我是s1</span>
    <div class="box2">我是box2</div>
</body>
</html>

4.w3导航条

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .all{
            width: 10000px;
        }

        a{
            text-decoration: none;
            color: rgb(119,119,119);
        }


        a:hover{
            color: white;
        }
        
        a:hover .link{
            background-color: rgb(63,63,63);
        }

        .link{
            padding-top: 28px;
            width: 200px;
            height: 50px;
            float: left;
            background-color: rgb(230,229,225);
            text-align: center;
            vertical-align: middle;
        }

        .link:hover{
            background-color: rgb(63, 63, 63);
        }

        .link:hover a{
            color: white;
        }

        

    </style>
</head>
<body>
    <div class="all">
            <!-- <div class="b1 link"> -->
                <a href="" class="link">HTML/CSS</a>
            <!-- </div> -->
        <!-- <div class="b2 link"> -->
            <a href="" class="link">Browser Side</a>
        <!-- </div> -->
        <!-- <div class="b3 link"> -->
            <a href="" class="link">Server Side</a>
        <!-- </div> -->
        <!-- <div class="b4 link"> -->
            <a href="" class="link">Programming</a>
        <!-- </div> -->
        <!-- <div class="b5 link"> -->
            <a href="" class="link">XML</a>
        <!-- </div> -->
        <!-- <div class="b6 link"> -->
            <a href="" class="link">Web Building</a>
        <!-- </div> -->
        <!-- <div class="b7 link"> -->
            <a href="" class="link">Reference</a>
        <!-- </div> -->
    </div>
</body>
</html>

5.简单布局

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style>
			*{
				margin: 0;
				padding: 0;
				list-style: none;
				text-decoration: none;
			}
			.w{
				margin: 0 auto;
			}
			header{
				width: 1000px;
				height: 120px;
				background-color: red;
			}
			main{
				width: 1000px;
				height: 400px;
				background-color: orange;
				margin: 10px auto;
			}
			.left{
				width:240px ;
				height: 400px;
				margin-right: 10px;
				background-color: burlywood;
				float: left;
			}
			.center{
				width: 500px;
				height: 400px;
				background-color: chartreuse;
				float: left;
			}
			.right{
				width: 240px;
				height: 400px;
				background-color: cyan;
				float: left;
				margin-left: 10px;
			}
			footer{
				width: 1000px;
				height: 120px;
				background-color: blue;
			}
		</style>
	
	</head>
	<body>
		<header class="w"></header>
		<main>
			<div class="left"></div>
			<div class="center"></div>
			<div class="right"></div>
		</main>
		<footer class="w"></footer>
	
		
	</body>
</html>

6.垂直布局

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 
        使用overflow属性设置父元素如何处理溢出的元素
          可选值:
            visible 默认值  文本正常显示
            hidden  裁剪掉多余的内容
            scroll  生成双向的滚动条,可以通过滚动条查看多余的内容
            auto    根据实际的内容出现滚动条

        overflow-x  对水平方向溢出的内容进行设置,垂直方向根据实际需要自动生成
        overflow-y  对垂直方向溢出的内容进行设置,水平方向根据实际需要自动生成
     -->
     <style>
        .box1{
            width: 200px;
            height: 200px;
            background-color: #bfa;
            overflow: scroll;
        }

        .p1{
            width: 200px;
        }
     </style>
     <!-- 块元素默认情况下,宽度是父元素内容区的100%,高度是被内容撑开
        在垂直布局中,一般情况下,我们是不设置高度的,让元素被内容撑开
     -->
</head>
<body>
    <div class="box1">
        <p class="p1">
            极得梵无小别张百回哉呼主价,活找都落风不恼案回子谭程若属井便国专属,份召至匹她是命远丈
        </p>
    </div>
</body>
</html>

7.外边距的折叠

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 
        垂直外边距的重叠
          -兄弟元素
            如果两个值都是正值,谁大听谁的
            如果两个值是负值,谁小听谁的(绝对值谁大听谁的)
            如果是一正一负,那最终的值,两者相加
          -父子元素
            如果父子元素的垂直外边距相邻了,则子元素的外边距会传递给父元素,导致父元素的位置发生变化,会影响到父元素下面的布局,所以这个问题必须解决
     -->

     <!-- 面试题:如黑解决父子外边距重叠的问题?
            1、不要用margin
            2、将父子外边距隔开,例如可以用边框,添加一个空表格
            3、开启元素的隐含属性BFC    overflow:hidden
    -->
    <style>
        /* .box1{
            width: 100px;
            height: 100px;
            background-color: red;
            margin-bottom: -50px;
        }
        .box2{
            width: 100px;
            height: 100px;
            background-color: green;
          
            margin-top: -90px;
        } */
                              
        .outer{
            width: 200px;
            height: 200px;
            background-color: green;
        }

        .inner{
            width: 100px;
            height: 100px;
            background-color: yellow;
        }
    </style>
</head>
<body>
    <!-- 兄弟元素 -->
    <!-- <div class="box1"></div> -->
    <!-- <div class="box2"></div> -->
    <div class="outer">
        <div class="inner">

        </div>
    </div>
</body>
</html>

8.内联元素的盒子

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* 从这几点分析:
            ·内容区:行内元素盒子模型不可以设置内容区的大小,它的内容区的大小都是被内容撑开的

            ·内边距: 行内元素盒子模型可以设置内边距,而且垂直方向的内边距不会影响其他的元素的位置

            ·边框:行内元素盒子模型可以设置边框,而且垂直方向的边框也不会影响其他的元素的位置

            ·外边距:水平方向的外边距是可以设置成功的,而且水平方向不会重叠;垂直方向的外边距不可以设置
        */
    </style>
</head>
<body>
    
</body>
</html>

9.默认样式

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入重制样式表
        注意:
            1、引入重置样式表前提是你要有这个reset.css文件
            2、引入重置样式表必须要在你写的样式的前面,否则会重置你写的样式

     -->
     <link rel="stylesheet" href="./reset.css">
    <style>
        /* 默认样式:
            浏览器为了在页面中没有样式时,也可以有一个比较好的显示效果,所以为很多的元素都设置了一些默认的margin和padding,而它的这些默认样式,正常情况下我们是不需要用的。
            所以我们往往在编写样式之前需要将浏览器中的默认的margin和padding
         */

         /* 方式一:
            1、清除浏览器的默认样式
            *{
                margin:0;
                padding:0;
            }

            li{
                text——decoration:none;
            }

            方式二:
            2、引入重置样式表
            这个表就是网上的大神列举出来的所有的标签的默认样式
            reset.css,normal.css
            我们使用的时候,只需要引入到对应的html文件内即可
            
          */
          a{
            text-decoration: none;
          }
    </style>
</head>
<body>
    
</body>
</html>

10.盒子的大小

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box1{
            width: 100px;
            height: 100px;
            background-color: red;
        }

        /* 面试题:简单说一下box-sizing的使用?

            默认情况下:盒子可见宽的大小由内容区,内边距,边框共同决定
               设置box-sizing  用来设置盒子尺寸的计算方式  用来规定width,height指的谁
            box-sizing  用来设置盒子尺寸
         */
    </style>
</head>
<body>
    
</body>
</html>

11.阴影和圆角

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* 知识点1:
            box-shadow
                用来设置元素的阴影效果,不会影响到页面布局
                    第一个值:水平偏移值 正->右 负->左 必写
                    第二个值;垂直偏移值 正->下 负->上 必写
         */

         /* 知识点2:
            1、border-radius    用来设置圆角
                可以同时设置多个值,规则跟我们之前归纳的boder-width一样
            2、单独设置某一角的圆角
                border-top-left-radius 左上
                border-top-right-radius 右上
                border-bottom-left-radius 左下
                border-bottom-left-radius 右下
            3、设置圆形
            border-radius:50%
          */
    </style>
</head>
<body>
    
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值