[英]How Do I Stop Parent Div From Expanding Because of Its Children?
So child div is has a list of items next to each other, each with a fix width.所以子 div 有一个彼此相邻的项目列表,每个项目都有固定的宽度。
In this image child div extends past MainContent but in the actual app, MainContent extends to fit the width of child div.在此图像中,子 div 扩展到 MainContent 之后,但在实际应用中,MainContent 扩展以适应子 div 的宽度。
I would like to make it so that when child overflows, it just has a scroll wheel instead of becoming so large.我想让它当孩子溢出时,它只有一个滚轮而不是变得那么大。
I have tried setting Child Div to 'overflow-x : auto'我试过将 Child Div 设置为 'overflow-x : auto'
Child div width is at 100%, as is MainContent.子 div 宽度为 100%,MainContent 也是如此。
JSX/HTML JSX/HTML
<div className = 'app'>
<div className = 'navbar'></div>
<div className = 'maincontent'>
<div className = 'child'>
<div className = 'childlist'>
<button className = 'btn'></button>
<button className = 'btn'></button>
<button className = 'btn'></button>
</div>
</div>
</div>
</div>
CSS CSS
.app : {
display : flex,
width: 100vw,
height :100vh
}
.navbar : {
display : flex,
flex-direction :column,
width : 112
}
.maincontent:{
display : flex,
width : 100%
}
.child: {
width :100%
}
.childlist:{
display : flex,
width :90%
}
.btn:{
width : 200,
height :200
}
All your containers widths are relative, so it will adjust, not overflow.你所有的容器宽度都是相对的,所以它会调整,而不是溢出。 If your child's width is % of the parent's, then it'll never overflow.
如果您孩子的宽度是父母的 %,那么它永远不会溢出。
You need to have fixed width to make it overflow.您需要具有固定宽度才能使其溢出。
Plus your code looks really messy, you may want to try Prettier加上你的代码看起来很乱,你可能想试试 Prettier
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.