html - CSS - 使用绝对位置设置子宽度大于父宽度
问题描述
我正在设计一个列表项,一切正常,但面临一个问题,即通过定位将子项的宽度设置为大于父项的宽度absolute
。这是我做过的代码
.container {
margin: 5rem;
}
.listing {
width: 50px;
height: 50px;
background-color: #333C83;
clip-path: polygon(25% 5%, 100% 0%, 75% 95%, 0% 100%);
display: flex;
justify-content: center;
align-items: center;
}
.circle {
width: 25px;
height: 25px;
border-radius: 50%;
background-color: #0A0D1E;
display: flex;
justify-content: center;
align-items: center;
}
.secondaryCircle {
width: 15px;
height: 15px;
border-radius: 50%;
background-color: #FABC42;
position: relative;
}
.line {
height: 5px;
background-color: #FABC42;
width: 40px;
position: absolute;
top: 4.5px;
left: 14px;
}
<div class="container">
<div class="listing">
<div class="circle">
<div class="secondaryCircle">
<div class="line"></div>
</div>
</div>
</div>
</div>
如您所见,线不可见,宽度为40px
. 我怎样才能解决这个问题 ?
这是我想要的输出
解决方案
.listing
这是因为类中的这个 css
.listing { clip-path: polygon(25% 5%, 100% 0%, 75% 95%, 0% 100%); }
它往往会裁剪掉盒子的边缘。尝试使用transform:skew
来实现您想要的特定目标..
我提供了一个例子。随意调整它。
.container {
margin: 5rem;
}
.listing {
width: 40px;
height: 50px;
background-color: #333C83;
transform: skewY(-12deg);
display: flex;
justify-content: center;
align-items: center;
}
.circle {
width: 25px;
height: 25px;
border-radius: 50%;
background-color: #0A0D1E;
display: flex;
justify-content: center;
align-items: center;
transform: skewY(12deg);
}
.secondaryCircle {
width: 15px;
height: 15px;
border-radius: 50%;
background-color: #FABC42;
position: relative;
}
.line {
height: 5px;
background-color: #FABC42;
width: 40px;
position: absolute;
top: 4.5px;
left: 14px;
}
<div class="container">
<div class="listing">
<div class="circle">
<div class="secondaryCircle">
<div class="line"></div>
</div>
</div>
</div>
</div>
推荐阅读
- c# - 如果满足条件,从列表中删除行的方法
- python - .NoReverseMatch:未找到带有参数“(”,)“的“作者详细信息”的反向。尝试了 1 种模式:['catalog/author/(?P
[0-9]+)$'] - kubernetes - 在 kubernetes 中使用 traefik v2 添加基本身份验证未弹出登录表单
- sql - 使用 SAS 在同一列中进行条件减法
- java - java/JSON 未显示解析 JSON 所需的值
- docker - Fluentd 日志驱动程序标记设置不起作用
- python - python matplotlib如何绘制20个或所需的数字唯一和不同的颜色而不是渐变颜色
- c++ - 在 float[4] 和 qbytearray 之间转换
- javascript - 复制另一个页面中使用的组件
- javascript - React Storybook 无法识别故事