简体   繁体   English

HTML使子div扩展到父div之外(宽度:9999px)

[英]HTML make child div expand beyond parent div (without width: 9999px)

I'm having a hard time with HTML/CSS now. 我现在很难使用HTML / CSS。 I'd love to create some sort of a slider with images placed side by side with hidden overflow (so when you press "next" arrow it will "move" pictures to the left (hiding the left one and showing the one that was hidden). 我很想创建一种滑块,将图像与hidden overflow并排放置(因此,当您按“下一个”箭头时,它将向左“移动”图片(隐藏左侧的图片并显示被隐藏的图片) )。

The problem is I can't make my div to go beyond its parent thus I can't line up my images side by side. 问题是我无法使div超出其父级,因此无法并排排列图像。

It looks like this: 看起来像这样:

 <div id="slider"> <div id="images"> <div class="image_container"> <img src="" alt="1"/> </div> <div class="image_container"> <img src="" alt="2"/> </div> ... <div class="image_container"> <img src="" alt="3"/> </div> </div> </div> 

Where #slider should be at 95% of width and preferably height based on content, #images should have "no width" - it should be based on the content and max-height ~, .image_container should have the width of the img - these should line up one next to another. 其中#slider的width应为95%width ,最好是基于内容的高度,而#images宽度应为“ no width”-它应基于内容,并且max-height .image_container.image_containerwidth应为img的width -这些应该排成一排。

Any ideas how can I achieve that? 有什么想法可以实现吗? I've been trying lots of things and none of them work. 我一直在尝试很多事情,但没有一个起作用。

Set the display property of the child elements to inline-block and the white-space property of the parent to nowrap . 将子元素的display属性设置为inline-block ,将父元素white-space属性设置为nowrap

 #parent{ background:#000; height:100px; padding:5px; white-space:nowrap; width:200px; } #parent>div{ display:inline-block; height:100%; width:100%; } #parent>div:nth-child(odd){background:#f00;} #parent>div:nth-child(even){background:#0f0;} 
 <div id="parent"><div></div><div></div><div></div><div></div><div></div></div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM