html - 如何定位一个元素,就好像它是相对的但有属性就好像它是绝对的?
问题描述
假设我要制作一个div。我想相对定位它,比如在通常位置的右侧 100 像素。但是,我希望所有其他 div 忽略它,就好像它是绝对定位一样。我该怎么做?
解决方案
有2个元素在另一个。第一个简单的position: absolute;
while inner has position: relative; right: 100px
。将需要的任何内容放入其中.inner
body {
counter-reset: foo-counter;
}
div {
width: 100px;
height: 100px;
display: inline-block;
border: 1px solid rgba(0, 0, 0, .3);
background-color: rgba(0, 0, 0, .1);
text-align: center;
}
div:not(.pop):before {
counter-increment: foo-counter;
content: "# " counter(foo-counter);
}
.pop {
text-align: left;
position: absolute;
background-color: rgba(120, 0, 0, .7);
}
.pop:before {
counter-increment: foo-counter;
content: "# " counter(foo-counter);
}
.inner {
position: relative;
top: 20px;
right: 20px;
background-color: rgba(0, 40, 0, .2);
}
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div class="pop"><div class="inner"></div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
推荐阅读
- css - CSS避免列在容器中“传播”
- php - 创建一个具有树查询的sql语句?SQL
- linux - 结构“struct page”存储在linux内核的哪里?
- c++ - fRead 方法的差异
- regex - 字符串中没有点序列
- bash - 为 bash 命令转义 perl 反引号中的括号
- java - 如何在java中的android studio上压缩视频
- c# - 如何编写一个包含所有导航属性的通用实体 getter 方法?
- django - 未找到带有参数 '('',)' 的 'editar_arvore' 的反向操作。尝试了 1 种模式:['arvore/editar_arvore/(?P
[0-9]+)/$'] - python - 我想在 python3 中将值从 12.56 更改为 12.57(四舍五入)