html - 在居中、固定位置的 div/overlay-box 中居中和定位元素

标签 html css positioning

我正在尝试将元素居中定位,并尝试将元素定位在一个固定的居中框内的其他位置,该框覆盖(当用户滚动时,覆盖框保持原样)我的整个移动网站。

我附上了一张图像图来展示我正在努力实现的目标: Diagram

额外的细节包括:

  • “叠加层”的宽度和高度取决于用户移动设备的宽度和高度。即,宽度:80%;高度:60%;.
  • 我希望图表右上角的图像在我的网站上始终保持这种状态(尽可能远地位于该 Angular )。

非常感谢任何帮助。干杯。

最佳答案

检查代码。这主要需要使用相对和绝对定位。您可以稍微调整一下以满足您的需求

HTML

<div class="body" style="position:relative">
<div class="box">
    <div class="box1"></div>
    <div style="clear:both;height:20px"></div>
    <div class="child"></div>  
    <div style="clear:both;height:20px"></div>
    <div class="child"></div>  
</div>
</div>​

CSS

.body{
width:400px;
height:250px;
background-color:#888;
}
.box{
width:80%;
height:150px;
border:1px solid #FFF;
position:relative;
margin:auto;
top:10%;
}
.child {
height:10px;
width:50px;
position:relative;
margin:auto;
background-color:red;
}
.box1{
width:10%;
height:10%;
border:1px solid #FFF;
position:absolute;
top:0;
right:0;
}

我也添加了 fiddle 。 http://jsfiddle.net/nQvEW/176/

关于html - 在居中、固定位置的 div/overlay-box 中居中和定位元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14083972/

相关文章:

html - Css 页脚定位

html - 在中心容器内 float 左 div

html - 显示保存在 mysql 数据库中的出版物时,文本从 css 框出现

html - 居中 img

php - 如何确保表格标题与表格在同一页上?

html - 我的图像图标拒绝在 anchor 标记内对齐中心或向内移动

javascript - webpack如何压缩HTML代码中的链接CSS文件?

html - 将 div 拉伸(stretch)到页面底部

html - 为什么 Z-index 在这里不起作用?

html - 如何让 div float 在彼此旁边和下方