0723 HTML background/float/margin/position || position(absolute,relative) / 小广告

 盒子模型 
      div(内-->外)
          内容(content)  内边距(填充,padding)边框(border),外边距(margin)
     两种盒子
         a.块级元素
              div  p  h1 table form -->前后会自动换行
              一行只能容纳一个盒子
              可以设置内容的宽和高

         b.内联元素
                img   span  input...
                前后不会自动换行,必须通过<br/> 才能换行
                一行可以容纳多个内联元素
               不能设置宽和高

          网页布局主要使用块级元素
          网页布局(css+div)
              a.浮动
              b.定位     


 
  浮动
     文档流的概念
        浏览器对网页元素自然的布局(文档流,标准流)
        块级元素 从上往下布局
        内联元素从左往右布局

     浮动即脱标
       盒子一旦浮动就会脱离原来的文档流
     左浮与右浮
     清除浮动 
     浮动布局(重点)
        块级元素在父元素中居中,设置 margin: 0 auto;

   定位
      静态定位(默认值)
      绝对定位 (脱标)
             position:absolute
             相对body
                left,right, top,bottom 相对于body的边缘距离
            相对父元素
                将父元素和子元素都设置为绝对定位
                那么left,right,top,bottom都是相对于父元素移动
            使用z-index确定盒子层叠顺序
      相对定位(不脱标)
           position:relative;
           不脱离文档流
           left ,top,right,bottom是相对于自身原来的位置移动

           最常用的布局模式:子绝父相  
           将父元素设置为相对定位
           将子元素设置为绝对定位
           left right top bottom 子元素相对于父元素的边缘移动
           小米定位案例
      固定定位(脱标)
          小广告,不随也页面滚动

作业:
   以组为单位下载电商网站的静态页面
   至少包含:登陆 注册 主页 购物车 商品详情  生成订单


 

background  / float  / margin  / position  


<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
  <style type="text/css">
  	  .one{
  	  	width: 100px;
  	  	height: 100px;
  	  	background: red;
  	  }

  	  .two{
  	  	 width: 200px;
  	  	 height: 160px;
  	  	 background: blue;
  	  }

  	  p{
  	  	 width: 120px;
  	  	 height: 200px;
  	  	 background: pink;
  	  }

      span{
      	 width: 200px;
      	 height: 200px;
      	 background: yellow;
      }
  </style>
</head>
<body>
	<!-- 块级元素 -->
	<div class="one"></div>
	<div class="two"></div>
	 <p></p>
	<!--  内联元素 -->
	<span>hello</span>
	<input type="" name="" value="world">
</body>
</html>


<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
      <style type="text/css">
      	 .one{
      	 	width: 100px;
      	 	height: 100px;
      	 	background: red;
      	 	float:left;
      	 }
         .two{
         	width: 100px;
         	height: 100px;
         	background:green;
         	float:left;
         }


      </style>
    </head>
    <body>
    	<div class="one"></div>
    	<div class="two"></div>

    </body>
</html>


<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
    <style type="text/css">
        .main{
       	  width: 600px;
       	  border:3px solid #999;
       	  margin:auto;
       }
    	.top{
    		width: 600px;
    		height: 160px;
    		background: pink;
    	}
    	.center{
            width: 600px;
            height: 350px;
            background: #eee;
            /* margin-top:10px;
            margin-bottom:10px; */
            margin:10px 0px;
    	}

    	.footer{
    		width: 600px;
    		height: 100px;
    		background: green;
    	}

    	.left,.right{
    	    width: 285px;
    	    height: 350px;
    	    float:left;  
    	    margin-left: 10px; 	    
    	}
        .left{
        	background: blue;
        }
        .right{
        	background: yellow;
        }


    </style>
    </head>
    <body>
       <div class="main">
        <div class="top"></div>
        <div class="center">
          <div class="left"></div>
          <div class="right"></div>   
        </div>
        <div class="footer"></div>
      </div>
    </body>
</html>

 


<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <style type="text/css">
        	.one{
        		width: 100px;
        		height: 100px;
        		background: red;
        		position:absolute;
        		left:100px;
        		top:100px;
        		z-index:1;

        	}
        	.two{
        		width: 100px;
        		height: 100px;
        		background: green;
        		position:absolute;
        		left:120px;
        		top:120px;
        		z-index:2;

        	}

        	.box{
        		width: 500px;
        		height:300px;
        		border:3px solid blue;
        		position:absolute;
             }

        </style>
    </head>
    <body>
    	
    	
  <div class="one"></div>
  <div class="two"></div>

    </body>
</html>

 

 position(absolute,relative) / bottom ,right ,left ,up  / 小广告

 


<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
       <style type="text/css">
       	   .one{
       	   	  width: 100px;
       	   	  height: 100px;
       	   	  background: red;
       	   	 /*  position:relative; */
       	   	  position:absolute;
       	   	  right:50px;
       	   	  bottom:10px;        //底部
       	   }

       	   .two{
       	   	  width: 100px;
       	   	  height: 100px;
       	   	  background: green;
       	   }

       	   .box{
       	   	  width: 600px;
       	   	  height: 350px;
       	   	  border:3px solid blue;
       	   	  position:relative;
       	   }

       </style>
    </head>
    <body>
       <div class="box">
    	<div class="one"></div>
       </div>
    	<!-- <div class="two"></div> -->
    </body>
</html>


<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
      <style type="text/css">
      	  .main{
      	  	 position:relative;
      	  	 width: 1226px;
      	  	 margin:auto;
      	  }
      	  .left-bar{
      	  	  position:absolute;
      	  	  left:0px;
      	  	  top:0px;
      	  }
      	  .left,.right{
      	  	 position:absolute;
      	  }
      	   .left{
      	   	  left:245px;
              bottom:166px;      	   	   
      	   }
      	   .right{
      	   	   right:10px;
      	   	   bottom:166px;   
      	   }

      </style>
    </head>
    <body>
    	<div class="main">
    		<img src="images/111.jpg"/>
    	  <div class="left-bar">
    	  	  <img src="images/xiaom_left.png"/>
    	  </div>
    	  <div class="left">
    	  	 <img src="images/left.png">
    	  </div>
    	  <div class="right">
    	  	  <img src="images/right.png">
    	  </div>
    	</div>
    </body>
</html>


<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
      <style type="text/css">
      	 .adv{
      	 	 width: 130px;
      	 	 height: 130px;
      	 	 background: green;
      	 	 position:fixed;
      	 	 right:0px;
      	 	 bottom:0px;
      	 }

      </style>
    </head>
    <body>
    	<div class="adv">小广告</div>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    	<p>you can you up</p>
    </body>
</html>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值