我正在使用reactjs
,当前无法将下面创建的水平线扩展到100%宽度。
这是由于它上面的div占据了80%的屏幕,因此我的元素也有80%。
有没有我可以扩展我的元素“水平线”到100%的宽度,而不修改它的父元素?
const HorizontalLine = () => {
return <section className="line"></section>;
};
export default HorizontalLine;
.line {
display: flex;
flex-wrap: nowrap;
flex-grow: 1;
width: 100%;
border-top: 1px solid grey;
}
下面是我正在处理的页面的结构。 如上所述,我不允许修改父页的结构。
<div class="main-content">
<div>
<div class="page">
<div class="page-header">
<div class="page-title">
</div>
<section className="line"</section> # My element is located here
</div>
</div>
</div>
.page {
display: flex;
justify-content: space-between;
align-items: center;
flex-direction: row;
margin-bottom: 30px;
}
如有任何帮助,我们将不胜感激。
要使行从当前节中中断,并具有填充页宽度,请将以下内容添加到.line
类:
.line{
position:absolute;
left:0;
}
您可以另外添加width:100vw;
,以确保行覆盖页面的100个虚拟宽度。
您可以在.line
:
flex-grow: 0;
flex-shrink: 0;
flex-basis: 100%;
但这将对.page
的其他子级产生影响,它们将缩小