5

#yyds干货盘点# 前端歌谣的刷题之路-第一百三十三题-定位-relative

 1 year ago
source link: https://blog.51cto.com/u_14476028/5783062
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

我是歌谣 我有个兄弟 巅峰的时候排名c站总榜19 叫前端小歌谣 曾经我花了三年的时间创作了他 现在我要用五年的时间超越他 今天又是接近兄弟的一天人生难免坎坷 大不了从头再来 歌谣的意志是永恒的 放弃很容易 但是坚持一定很酷 本题目源自于牛客网 微信公众号前端小歌谣

 相对定位的元素仍然会待在原来的地方,即不会从流中出来。此后可以通过"top"、"right"、"bottom"和"left"属性使元素相对于初始位置进行移动。现在给类名为"center"的盒子设置相对定位属性"position: relative"、设置"left: 50px"、设置"top: 50px",再自定义背景颜色以便于观察。此时可以观察到中间盒子在原始的位置上向右、向下均移动了50px的距离,并且保留了原来的空间。
 完成以上所讲的步骤即可通过测试,进入下一节的学习吧。

#yyds干货盘点# 前端歌谣的刷题之路-第一百三十三题-定位-relative_html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>relative</title>
</head>
<style type="text/css">margin: 0;
padding: 0;
}
.left {
width: 100px;
height: 100px;
background-color: black;
}
.center {
width: 100px;
height: 100px;
position: relative;
background-color: red;
left: 50px;
top: 50px;
}
.right {
width: 100px;
height: 100px;
background-color: yellow;
}
</style>
<body>
<div class="left"></div>
<div class="center"></div>
<div class="right"></div>
</body>
</html>

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK