[英]Absolutely positioned div
I have the following html: 我有以下html:
<!DOCTYPE html>
<html>
<head>
<title>JBA</title>
<style type="text/css">
body {
margin:0;
padding:0;
}
#layout {
float: left;
}
#title {
padding: 10px;
border: 1px solid #ccc;
position: relative;
}
#content {
position: absolute;
top: 26px;
left: 0;
right: 0;
bottom: 0;
border: 1px solid #ccc;
}
</style>
</head>
<body>
<div id="layout">
<label id="title">Below is content:</label>
<div id="content">
</div>
</div>
</body>
<script>
</script>
</html>
What I need is to position #content div right below the #title label. 我需要将#content div放在#title标签的正下方。 However, float and position settings shouldn't be changed.
但是,浮动和位置设置不应更改。 So, how to calculate #content's top?
那么,如何计算#content的顶部? 26px seems to work for Chrome but, for IE it needs to be 28px.
26px似乎适用于Chrome,但对于IE,它必须为28px。 Why?
为什么?
give position relative to the "#layout" div 给出相对于“ #layout” div的位置
#layout {
float: left;
position:relative;
}
I have tested it in chromium as well as IE9. 我已经在铬以及IE9中对其进行了测试。 For both position top: 28 is working properly.
对于两个位置的顶部:28正常工作。 Screenshot is attached.
屏幕截图已随附。
您应该在#content上将padding和margin设置为0,因为浏览器呈现的方式不同(即使未设置)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.