DIV-Elemt 绝对(!) 定位
DIV-Elemt absolute(!) positioning
首先为所有人:不,我不是在寻找属性位置:绝对;
我想要创建一个显示一些文本的字段。我想在页面中间准确地显示该字段,然后淡出背景,没关系,div 在代码中的位置。
目前它看起来像这样:https://www.dropbox.com/s/wiljdh1xjj3we1c/Capture1.PNGhttps://www.dropbox.com/s/chw7pdes5fdcj3u/Capture2.PNG
如何将 Elemtn ABSOLUTE 放在页面中间,无论它写在代码中的哪个位置?
现在我可以说好吧,我会把它放在内容之上。但问题是,在这个字段中显示的是一些在内容中生成的信息,所以我不得不把它放在内容之后的代码中。
我希望,有人可以帮助我:)
PS:如果您有其他解决方案来解决这样的事情...欢迎告诉我!我只想要像alert();-Box这样的东西,具有我自己的风格。
编辑:一些努力:(基本上已经与屏幕截图一起显示,但这里有一些代码;只是不想让它变得混乱)
我将文本保存如下:
// Save Help-Text
ob_start();
?>
This is the main page. There is no help available!
<?php
$help = ob_get_clean();
我按如下方式显示文本:(echo create_help($help); 创建帮助标记并显示它)
function create_help($content){
$help = "
<div id='"help-bg'" class='"closehelp'" ></div>
<div id='"help'" >
<img src='"../images/close.png'" class='"closehelp'" />
$content
</div>
";
return $help;
}
这是该框的 CSS:
/* Help-box style */
#help
display: none;
position: absolute;
margin-left: auto;
margin-right: auto;
background-color: #B8DBFF;
border: 5px solid rgb(58, 100, 250);
border-top: 30px solid rgb(58, 100, 250);
border-radius: 5px;
padding: 20px;
width: 600px;
z-index: 1001;
#help img
position: absolute;
margin-left: 595px;
margin-top: -47px;
height: 25px;
width: 25px;
/* Makes background of Help-box transparent black */
#help-bg
background-color: black;
z-index: 1000;
width: 100%;
height: 100%;
position: fixed;
left: 0px;
top: 0px;
opacity:0.6;
display: none;
首先,我建议使用 position:fixed;
而不是 position:absolute;
,因为警报会在页面内滚动。如果您有固定的高度和宽度,请尝试类似 margin: -150px 0 0 -150px;
left: 50%;
top: 50%;
.此 CSS 代码将水平和垂直地将您的div 居中(演示 -> http://demo.tutorialzine.com/2010/03/centering-div-vertically-and-horizontally/demo.html)。但是如果你使用动态高度,也许你应该考虑使用jQuery或给它一个固定的顶部位置。
试试这个:
html, body{
position: relative;
}
.yourAbsoluteClass{
position: absolute;
width: 50%;
top: 25%;
left: 50%;
}
- 绝对定位不适用于Javascript DIV
- stickyfloat无法处理绝对定位的元素
- 如果元素在容器外部,是否可以相对于容器以绝对定位来定位该元素
- 当打开绝对定位下拉菜单时,页面将滚动到顶部
- 如何快速找到一个绝对定位的子元素的相对定位的HTML父元素
- 当一个元素中有绝对定位的子元素时,获取该元素的全宽
- 如何为 ajax 生成的图像设置绝对定位
- DIV-Elemt 绝对(!) 定位
- 图像(绝对定位)相对定位容器中的水平中心
- 如何在页面顶部放置一个绝对定位的img
- 相对+绝对定位
- positon元素相对于JS中的parent.part容器?没有绝对/固定的定位
- 使用Raphael.js可以相对定位一个元素,然后将其偏移一个绝对单位
- 使用绝对定位在内容上方显示图像
- 同位素JS绝对定位
- 不会转义视口的绝对定位元素
- Z 索引绝对定位元素低于父级,具有 z 索引解决方法
- 为图像上绝对定位的文本块添加换行符以创建文本条带
- 与位置的相对定位:绝对
- 通过偏移定位绝对元素