[英]Make child element go through beyond its parent width [duplicate]
This question already has an answer here: 这个问题已经在这里有了答案:
I want to make child element to go beyond it's parent element. 我想使子元素超出其父元素。 So further the parent element can apply
overflow-x: scroll
. 因此,父元素可以进一步应用
overflow-x: scroll
。 Here some illustration on what I want to achieved, and what I got: 以下是我要实现的目标以及获得的目标的一些说明:
I have tried to solve the problem through applying display: inline-block
to child element, or trying find out from similar question. 我试图通过将
display: inline-block
应用于子元素来解决问题,或者尝试从类似的问题中找出答案。 but it hasn't solved my problem yet. 但这还没有解决我的问题。 Here is the html:
这是html:
<div class="parent">
<div class="child">Child Element</div>
<div class="child">Child Element</div>
<div class="child">Child Element</div>
<div class="child">Child Element</div>
<div class="child">Child Element</div>
</div>
Every child has a different width which if it added up will exceed parent width. 每个孩子都有不同的宽度,如果加起来,它将超过父母的宽度。 Is there any solution or hint?
有什么解决方案或提示吗?
try this 尝试这个
.parent{ max-width: 100%; overflow-x: scroll; white-space: nowrap; } .child{ display: inline-block; }
<div class="parent"> <div class="child">Child Element</div> <div class="child">Child Element</div> <div class="child">Child Element</div> <div class="child">Child Element</div> <div class="child">Child Element</div> </div>
I make a demo for you. 我为您制作一个演示。
.child1, .child3, .child4{ width: 100px; float: left; border: 1px solid red; text-align: center; padding: 10px; } .child2, .child5{ width: 300px; float: left; border: 1px solid yellow; text-align: center; padding: 10px; } .parent{ width: 1500px; } .scroll{ max-width: 500px; width: 100%; overflow-x: auto; border: 1px solid #000; padding: 30px; }
<div class="scroll"> <div class="parent"> <div class="child1">Child Element</div> <div class="child2">Child Element</div> <div class="child3">Child Element</div> <div class="child4">Child Element</div> <div class="child5">Child Element</div> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.