css应用

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        #span1{
            margin-right: 20px;
            background-color: lightgreen;
        }
        #span2{
            margin-left: 30px;
            background-color: pink;
        }
        #d1{
            height: 100px;
            background-color: lightcoral;
            margin-bottom: 20px;
        }
        #d2{
            height: 100px;
            background-color: lightblue;
            margin-top: 30px;
        }
    </style>
    <title>行级标签、块级标签之间的距离</title>
</head>
<body>

<!--水平排放的盒子,水平间距是margin的累加-->
<span id="span1">节日风俗</span><span id="span2">节日风俗</span>
<br>
<br>

<!--垂直排放的盒子,垂直间距是合并的(取最大值)-->
<div id="d1">盒子属性</div>
<div id="d2">盒子属性</div>

</body>
</html>


盒子嵌套:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <style>
        /*解决外边距失效问题
           1:为父盒子添加overflow:hidden
           2、为父盒子添加padding
           3、为父盒子添加border   */
        #p{
            width: 300px;
            height: 300px;
            background-color: lightcoral;
            /*padding: 25px;*/
            overflow: hidden;
        }
        #c{
            width: 150px;
            height: 150px;
            background-color:lightblue;
            margin: 0 auto;
            margin-top: 75px;
        }
    </style>

    <title>嵌套的盒子</title>
</head>
<body>


<div id="p">
    <div id="c"></div>
</div>

</body>
</html>


负边距DIV居中:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <style>
        #t1{
            width: 300px;
            height: 300px;
            background-color: lightcoral;
            position: relative;
        }
        #t2{
            width: 150px;
            height: 150px;
            background-color: lightblue;
            position: absolute;
            /*margin: 0 auto;*/
            left: 50%;
            margin-left: -75px;
            top: 50%;
            margin-top: -75px;
        }
    </style>

    <title>负边距DIV居中</title>
</head>
<body>

<div id="t1">
   <div id="t2"></div>
</div>

</body>
</html

固定定位:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <style>
        #back{
            width: 120px;
            height: 80px;
            text-align: center;
            line-height: 80px;
            background-color: lightcoral;
            position: fixed;
            bottom: 80px;
            right: 20px;
            /*z-index默认值为:1 其数值越大越靠前*/
            z-index: 1000;
        }
    </style>

    <title>固定定位</title>
</head>
<body>
<div style="height: 1000px">
    <div id="back">
        返回页面顶部
    </div>
</div>

</body>
</html>

效果图:



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值