我有一个相对定位的父元素。我在各自的 Angular 落(左上角和右上角)也有两个绝对定位的子元素。但是,这两个元素都不会出现在 DOM 中。我在这两个元素上都有明确的高度和宽度。我还尝试更改两个元素的 z-index
无济于事。
这是标记和 CSS:
.first_customer, .all_customer {
flex: 1 1 0;
display: flex;
justify-content: center;
align-items: center;
position: relative;
}
.inner {
text-transform: uppercase;
width: 100%;
}
.inner > * {
margin: 20px auto;
background-color: #fad63a;
padding: 7px;
border-radius: 3px;
box-shadow: inset 0 0 10px #000;
border: 1px solid #fff;
text-align: center;
width: 85%;
}
.inner > h4 {
font-size: 10px;
}
.inner > h6 {
font-size: 10px;
}
.inner > p {
font-size: 10px;
}
.topleftcorner, .toprightcorner {
position: absolute;
min-width: 100px;
min-height: 100px;
}
.topleftcorner {
top: 0;
left: 0;
z-index: 2;
}
<div class="first_customer">
<div class="topleftcorner"></div>
<div class="toprightcorner"></div>
<div class="inner">
<h4>New Customers</h4>
<h6>$10 Gift</h6>
<p>Dry Cleaning</p>
</div>
</div>
最佳答案
它已经开始工作了。我只是添加了背景颜色和位置右侧的 div。
.first_customer,.all_customer{
flex: 1 1 0;
display: flex;
justify-content: center;
align-items: center;
position: relative;
}
.inner{
text-transform: uppercase;
width: 100%;
}
.inner > *{
margin: 20px auto;
background-color: #fad63a;
padding: 7px;
border-radius: 3px;
box-shadow: inset 0 0 10px #000;
border: 1px solid #fff;
text-align: center;
width: 85%;
}
.inner > h4{
font-size: 10px;
}
.inner > h6{
font-size: 10px;
}
.inner > p{
font-size: 10px;
}
.topleftcorner,.toprightcorner{
position: absolute;
width: 100px;
height: 100px;
background-color: #000;
}
.topleftcorner{
top: 0;
left: 0;
z-index: 2;
}
.toprightcorner {
top: 0;
right: 0;
z-index: 2;
}
<div class="first_customer">
<div class="topleftcorner"></div>
<div class="toprightcorner"></div>
<div class="inner">
<h4>New Customers</h4>
<h6>$10 Gift</h6>
<p>Dry Cleaning</p>
</div>
</div>
关于html - 绝对位置 div 不工作 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50185732/