码迷,mamicode.com
首页 > Web开发 > 详细

Web从入门到放弃<8>

时间:2018-02-25 15:53:14      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:http   jquery   type   z-index   box   inline   hid   rdb   意思   

Ref:

Cameron D. - HTML5, JavaScript and jQuery (Programmer to Programmer) - 2015

<1> CSS Responsive box  

 技术分享图片

 

关键字:display:inline-block;

html:

技术分享图片
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <style>
        .box {
            height:200px;
            width:200px;
            display:inline-block;
        }
    </style>
</head>
<body>
<div class="box" style="background:red"></div>
<div id="middleBox" class="box" style="background:green"></div>
<div id="thirdBox" class="box" style="background:blue"></div>
<div id="lastBox" class="box" style="background:yellow"></div>

</body>
</html>
View Code

 

如果要把绿色的立方体移动50px,把蓝色向右推动50px,在这种静态布局是不可能的.先试试position:relative.

技术分享图片

技术分享图片
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <style>
        .box {
            height:200px;
            width:200px;
            display:inline-block;
        }
        #middleBox{
            position: relative;
            left:50px;
        }

    </style>
</head>
<body>
<div class="box" style="background:red"></div>
<div id="middleBox" class="box" style="background:green"></div>
<div id="thirdBox" class="box" style="background:blue"></div>
<div id="lastBox" class="box" style="background:yellow"></div>

</body>
</html>
View Code

position设置为relative,意思就在现在的位置作为基础,然后再做移动。 

 

position设置为absolute:

技术分享图片
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <style>
        .box {
            height:200px;
            width:200px;
            display:inline-block;
        }
        #middleBox{
            position: absolute;
            left:150px;
            top:150px;
        }

    </style>
</head>
<body>
<div class="box" style="background:red"></div>
<div id="middleBox" class="box" style="background:green"></div>
<div id="thirdBox" class="box" style="background:blue"></div>
<div id="fourthBox" class="box" style="background:yellow"></div>
<div id="lastBox" class="box" style="background:black"></div>
</body>
</html>
View Code

 

技术分享图片

要把绿色放入下面写:z-index:-1;

 

Web从入门到放弃<8>

标签:http   jquery   type   z-index   box   inline   hid   rdb   意思   

原文地址:https://www.cnblogs.com/gearslogy/p/8469362.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!