老师你好,想问关于移动量的问题

老师你好,想问关于移动量的问题

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<meta http-equiv="X-UA-Compatible" content="ie=edge">

<title>Document</title>

<style>

*{padding: 0;margin: 0;}

.page{ width: 100%;height: 4000px;

background: url(http://img1.sycdn.imooc.com/climg//59c9f7ce0001839219034033.png)

center top no-repeat;}

.banner1{width: 200px;height: 250px;

background: url(http://img1.sycdn.imooc.com/climg//5a3383d00001a3dd02240364.png)no-repeat;

position: fixed; left:0;top: 50%; margin-top: -125px;}

.banner2{width: 200px;height: 250px;

background: url(http://img1.sycdn.imooc.com/climg//5a3383c70001f1b702240364.png)no-repeat;

position: fixed;right:0;top: 50%;margin-top: -125px;}

</style>

</head>

<body>

<div class="page">

<div class="banner1"></div>

<div class="banner2"></div>

</div>

</body>

</html>



比如我设置

margin-top: -125px;这个值,那他这个-125px是根据哪里开始移动的? 要是设置正的125pxz值又是怎么移动的呢,有点搞不懂是怎么移动的,是按照X轴Y轴的规则去移动的吗?


正在回答

登陆购买课程后可参与讨论,去登陆

1回答

你好同学,不管是正值还是负值,都是在原位置的基础上进行移动。例如图片没有设置上间距的时候,

设置left:50%之后,是它的上边缘位置居中显示:

http://img1.sycdn.imooc.com//climg/5d4568f20001aee307200926.jpg

当设置margin-top: -125px;之后,会根据上边缘的位置往上移动:

http://img1.sycdn.imooc.com//climg/5d4569420001e38909510937.jpg

祝学习愉快,望采纳。

  • Liu1997 提问者 #1
    现在能理解了,还是要多练习才行,谢谢老师!
    2019-08-04 09:28:07
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师