admin管理员组文章数量:1610836
absolute:生成绝对定位的元素,相对于 static 定位以外的第一个父元素进行定位。元素的位置通过 “left”, “top”, “right” 以及 “bottom” 属性进行规定。
fixed:生成绝对定位的元素,相对于浏览器窗口进行定位。元素的位置通过 “left”, “top”, “right” 以及 “bottom” 属性进行规定。(可用于固定菜单)
relative:生成相对定位的元素,相对于其正常位置进行定位。
static:默认值,无定位。
inherit:承接父元素的属性。
以下为一个相对浏览器的绝对定位demo,代码如下:
<!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>绝对/相对定位</title>
<style type="text/css">
body {
background-color: bisque;
}
div#all {
background-color: darkgrey;
color: white;
margin: auto;
width: 1300px;
}
div#all div {
float: left;
}
div#one,div#three {
background-color: dimgray;
width: 20%;
}
**div#fixed {
position: fixed;
background-color: dimgray;
width: 260px;
}**
div#two {
background-color: brown;
width: 60%;
height: 5000px;
}
</style>
<script type="text/javascript"></script>
</head>
<body>
<div id="all">
<div id="one">1
**<div id="fixed">相对浏览器窗口定位的盒子</div>**
</div>
<div id="two">2</div>
<div id="three">3</div>
</div>
</body>
</html>
其中出来的效果如下:
其中这个“相对浏览器窗口定位的盒子”,无论如何滑动滚轮都会被固定在这个位置。
本文标签: JavaScriptPosition
版权声明:本文标题:JavaScript初学——通过position解决定位问题 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1728606510a1165521.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论