html - 如何让背景形状定位在页面下方的部分中?- CSS
问题描述
我试图在我的 CSS 中围绕背景放置几个形状,但不知道该怎么做。它在我的英雄部分工作得很好——但那是在页面的顶部。这个在页面的中间位置,每当我将“绝对”设置为父级而“相对”设置为子级时,它会将元素定位在顶部。
例如,我希望我的第一个正方形在我的部分容器中距离顶部 12% 和距离左侧 23% 。然后我想将我的另外两个放置在页面上的其他随机 % 点。
这是我的代码:
.features-section {
height: auto;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.features-section li {
height: 50px;
width: 50px;
border-radius: 5%;
display: block;
list-style: none;
}
.features-section li:nth-child(1) {
top: 12%;
left: 23%;
background: #ffa299;
opacity: 0.5;
}
<section class="features-section">
<ul class="features-animation-list">
<li></li>
<li></li>
<li></li>
</ul>
</section>
形状将是 li:nth-child(2) / (3) 等,所以我只包括了一个。
任何指针?
解决方案
.features-section {
height: auto;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
position: relative; /*Set relative postion to parent*/
}
.features-section li {
height: 50px;
width: 50px;
border-radius: 5%;
display: block;
list-style: none;
position: absolute; /* Set absolute position to child*/
}
.features-section li:nth-child(1) {
top: 12%;
left: 23%;
background: #ffa299;
opacity: 0.5;
}
.features-section li:nth-child(2) {
top: 12%;
left: 40%;
background: #ffa299;
opacity: 0.5;
}
<section class="features-section">
<ul class="features-animation-list">
<li></li>
<li></li>
<li></li>
</ul>
</section>
推荐阅读
- sql - 雪花 sql 选择查询自动化
- python - 使用Python中的字典从文本文件中提取单词(查找和替换)
- python - 使用dense_vector的Elasticsearch脚本查询余弦相似度给出“class_cast_exception”错误
- css - 为什么“字体大小:calc(1em + 1vw)”在 Safari 上不起作用?(但我的解决方法是)
- cuda - 如果知道warp中所有线程的条件相同,如何避免在CUDA程序中执行条件的两个分支?
- node.js - 通过 reatjs 中的 multi-part/form-data 使用请求承诺上传文件
- javascript - 无法使用 httpclint 将数据从 ionic 5 发布到 laravel 6
- python - 从 Pandas DF 中删除包含列表中元素的行
- elasticsearch - Elasticsearch 将字符串与空格、列、破折号完全匹配
- javascript - 如何在输入中将数字“推”到左侧?