杂项 飘浮 (内外边距)

absolute
绝对定位,相对于 static 定位以外的第一个父元素进行定位。
元素的位置通过 “left”, “top”, “right” 以及 “bottom” 属性进行规定。
1.有祖先 靠近的
2.没有祖先 <body

relative
相对定位,相对于其正常位置进行定位。
1.参照自身 ,原位置保留 (自己走了别人也不能用)

fixed
固定定位,相对于浏览器窗口进行定位。
**

要求案例 实现下图(1)(2)

**
在这里插入图片描述

         ** 分割线       代码+运行结果图**


<html>
<head>
<title>制作网页</title>
<style type="text/css">

.box{
    position: absolute;
    top: 50%;
    margin-top: -100px;
    left: 50%;
    margin-left: -425px;

}
.div1{
    position: relative;
    top: 400px;
    left: 500px;
}
.div5{
    position: fixed;
    top: 500px;
    right: 50px;
}

</style>
</head>

<body>
<div class="box" style="width: 850;height: 800px;background: #666666;border:1px solid#000;">
   <div class="div1"  style="width: 300;height: 100px;background: rgba(255,0,0); float: left;">1</div>
   <div class="div2"  style="width: 500;height: 200px;background: rgba(0,0,255); float: right;">2</div>
   <div class="div3"  style="width: 200;height: 300px;background: rgba(0,255,0); float: right;">3</div>
   <div class="div4"  style="width: 400;height: 400px;background: rgba(0,0,0);   float: right;">4</div>
</div>
<div class="div5"  style="width: 100;height: 400px;background: rgba(66,66,0);">5</div>

</body>
</html>

在这里插入图片描述


<html>
<head>
<title>制作网页</title>
<style type="text/css">
.shangce1{
    float: left;
    top: 20;
    left: 20;
}
.shangce2{
    float: left;
    top: 20;
}
.shangce3{
   float: left;
    top: 20;
}
.zhongjian1{
    float: left;
}
.zhongjian2{
    float:right;
}
.zhongjian3{
    float: right;
}

</style>
</head>

<body>
    <div class="box" style="width: 780;height: 450px;background: rgb(236, 169, 169);border:2px solid#000;">
    <div class="shangce1" style="width: 200;height: 100px;px;background: rgb(255, 255, 255);border:2px solid#000;"><p>1</p></div>
    <div class="shangce2" style="width: 100;height: 300px;px;background: rgb(255, 255, 255);border:2px solid#000;"><p>2</p></div>
    <div class="shangce3" style="width: 300;height: 100px;px;background: rgb(255, 255, 255);border:2px solid#000;"><p>3</p></div>
    <div class="zhongjian1" style="width: 400;height: 100px;px;background: rgb(255, 255, 255);border:2px solid#000;"><p>4</p></div>
    <div class="zhongjian2" style="width: 300;height: 100px;px;background: rgb(255, 255, 255);border:2px solid#000;"><p>5</p></div>
    <div class="zhongjian3" style="width: 400;height: 100px;px;background: rgb(255, 255, 255);border:2px solid#000;"><p>6</p></div>
    
    </div>
</body>
</html>

在这里插入图片描述

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>制作网页</title>
<style type="text/css">
.shangce1{
position:absolute;
left: 20px;
top: 20px;
}
.shangce2{
position:absolute;
top:20px;
left:140px;
}
.shangce3{
position:absolute;
top:20px;
left:260px;
}
.zhongjian1{
position:absolute;
left:20px;
top:90px;
}
.zhongjian2{
position:absolute;
left:140px;
top:90px;
}
.zhongjian3{
position:absolute;
left:260px;
top:90px;
}
.xiamian1{
position:absolute;
left:20px;
top:160px;
}
.xiamian2{
position:absolute;
left:140px;
top:160px;
}
.xiamian3{
position:absolute;
left:260px;
top:160px;
}
</style>
</head>
<body>
<div class="box" style="width: 380px;height: 230px;background:#F9C;border:2px solid#000;">
<div class="shangce1" style="width: 100px;height: 50px; border: 1px solid#000;"><p>1</p></div>
<div class="shangce2" style="width: 100px;height: 50px; border: 1px solid#000;"><p>2</p></div>
<div class="shangce3" style="width: 100px;height: 50px; border: 1px solid#000;
"><p>3</p></div>
<div class="zhongjian1" style="width: 100px;height:50px;border:1px solid#000;"><p>4</p></div>
<div class="zhongjian2" style="width:100px;height:50px;border:1px solid#000;"><p>5</p></div>
<div class="zhongjian3" style="width:100px;height:50px;border:1px solid#000;"><p>6</p></div>
<div class="xiamian1" style="width:100px;height:50px;border:1px solid#000;"><p>7</p></div>
<div class="xiamian2" style="width:100px;height:50px;border:1px solid#000;"><p>8</p></div>
<div class="xiamian3" style="width:100px;height:50px;border:1px solid#000;"><p>9</p></div>
</div>
</body>
</html>

在这里插入图片描述

第2种方法

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>制作网页</title>
<style>
    .box{
        padding :10px;
    }
</style>
</head>
<body>
<div class="box" style="width: 380px;height: 230px;background:#F9C;border:2px solid#000;">
<div class="shangce1" style="width: 100px;height: 50px;float:left; margin:10px;border: 1px solid#000;"><p>1</p></div>
<div class="shangce2" style="width: 100px;height: 50px;float:left; margin:10px;border: 1px solid#000;"><p>2</p></div>
<div class="shangce3" style="width: 100px;height: 50px;float:left; margin:10px;border: 1px solid#000;
"><p>3</p></div>
<div class="zhongjian1" style="width: 100px;height:50px;float:left;margin:10px;border:1px solid#000;"><p>4</p></div>
<div class="zhongjian2" style="width: 100px;height:50px;float:left;margin:10px;border:1px solid#000;"><p>5</p></div>
<div class="zhongjian3" style="width: 100px;height:50px;float:left;margin:10px;border:1px solid#000;"><p>6</p></div>
<div class="xiamian1" style="width:100px;height:50px;float:left;margin:10px;border:1px solid#000;"><p>7</p></div>
<div class="xiamian2" style="width:100px;height:50px;float:left;margin:10px;border:1px solid#000;"><p>8</p></div>
<div class="xiamian3" style="width:100px;height:50px;float:left;margin:10px;border:1px solid#000;"><p>9</p></div>
</div>
</body>
</html>

在这里插入图片描述

未成功版本


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>制作网页</title>
</head>
<body>
<div class="box" style="width: 740px;height: 430px;background:#F9C;padding:5px;border:2px solid#000;">
<div class="shangce1" style="width: 200px;height: 100px;float:left; margin:5px ;border: 1px solid#000;"><p>1</p></div>
<div class="shangce2" style="width: 100px;height: 300px;float:left; margin:5px ;border: 1px solid#000;"><p>2</p></div>
<div class="shangce3" style="width: 300px;height: 100px;float:left; margin:5px ;border: 1px solid#000;
"><p>3</p></div>
<div class="zhongjian1" style="width: 400px;height:100px;float:left;margin:5px ;border:1px solid#000;"><p>4</p></div>
<div class="zhongjian2" style="width: 300px;height:100px;float:left;margin:5px ;border:1px solid#000;"><p>5</p></div>
<div class="zhongjian3" style="width: 400px;height:100px;float:right;margin:5px ;border:1px solid#000;"><p>6</p></div>
</div>
</body>
</html>

在这里插入图片描述

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>制作网页</title>
</head>
<body>
<div class="box" style="width: 740px;height: 430px;background:#F9C;padding:5px;border:2px solid#000;">
<div class="shangce1" style="width: 200px;height: 100px;float:left; margin:5px ;border: 1px solid#000;"><p>1</p></div>
<div class="shangce2" style="width: 100px;height: 300px;float:left; margin:5px ;border: 1px solid#000;"><p>2</p></div>
<div class="shangce3" style="width: 300px;height: 100px;float:left; margin:5px ;border: 1px solid#000;
"><p>3</p></div>
<div class="zhongjian1" style="width: 400px;height:100px;float:left;margin:5px ;border:1px solid#000;"><p>4</p></div>
<div class="zhongjian2" style="width: 300px;height:100px;position:absolute;top: 330px;left: 15px; margin:5px ;border:1px solid#000;"><p>5</p></div>
<div class="zhongjian3" style="width: 400px;height:100px;position:absolute;top: 330px;left: 330px; margin:5px ;border:1px solid#000;"><p>6</p></div>
</div>
</body>
</html>

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值