布局与定位

圣杯布局:

 <style>
    .main{
        width: 1000px;
        height: 500px;
        border: 1px solid red;
        margin:0 auto;
    }
    .header{
        width: 100%;
        height: 100px;
        background: lightblue;
    }
    .container{
        width: 100%;
        height: 300px;

    }
    .container .left{
        width:300px;
        height: 300px;
        float: left;
        background: lightcoral;
    }
    .container .center{
        width: 400px;
        height: 300px;
        float: left;
        background: lightsalmon;
    }
    .container .right{
        width: 300px;
        height: 300px;
        float: left;
        background: lightseagreen;
    }
    .footer{
        width: 100%;
        height: 100px;
        background: lightslategray;
    }
</style>

相对定位:

    <style>
	    .father{
        margin: 0 auto;
        width: 700px ;
        height: 700px;
        border: 1px solid red;

    }
    .son{
        margin: 100px auto;
        width: 200px;
        height: 200px;
        background: lime;
        position: relative;
        margin-top: 200px;
        /* 当你只有一个相对定位的时候 坐标轴是谁*/
        /* 其坐标原点是其原来的位置 */
    }

    /* 
    实际上定位有三种 
    相对定位 绝对定位 固定定位  
    定位的属性是 position 
    relative absolute fixed
    */

    /* 
        1)相对定位是不会脱离标准文档流的,他原本的位置还是被自己占着,别人是不能占用
        2)不管一个盒子 之前是什么性别  相对定位后 还是什么性别 性别是不会改变的
        3)一般情况下,我们一般都要通过使用left,top,right,bottom来设置偏移量 ,但是 position:relative这一行代码除了表示相对定位外 还有其他含义
        4)相对定位的应用场景,一般是用到对一个元素的位置进行微调
    */
</style>




</head>
<body>
<div class="father">
	    <div class="son">

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

固定定位:

 <	style>
    html{
        height: 300%;
    }
    .guanggao{
        width: 100px;
        height: 200px;
        border: 1px solid red;
        position: fixed;
        right: 0;
        bottom: 0;
    }
    /* 1.固定定位 没有参考点,就以body为参考点 */
    /* 2.固定定位也可以和margin同时使用 */
    /* 3.一般情况下 这种小广告 需要用到固定定位的东西 一般都是写在body的下一级 */
    /* .test{
        width: 100px;
        height: 100px;
        border: 1px solid red;
        overflow: scroll;
        position: relative;
    }
    .son{
        height: 200%;
    }
    .xiaoguanggao{
        width: 20px;
        height: 20px;
        position: fixed;
        background: lime;
        top: 0;
        right: 0;
    } */
</style>
<body>
<div class="guanggao">
    我是一个小广告,你来消灭我
</div>

<!-- <div class="test">
    <div class="son">
    </div>
    <div class="xiaoguanggao">
    </div>
</div> -->
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值