简体   繁体   English

结合溢流y:自动和溢流x:可见

[英]Combine overflow-y: auto and overflow-x: visible

I have read a lot of question here about combining the different overflow values. 我在这里已经阅读了很多有关合并不同的溢出值的问题。 However, I couldn't find a solution for my problem, which is the following. 但是,找不到以下问题的解决方案。

I have an image, which is larger than its container. 我有一个图像,它大于它的容器。 So, I want to make it visible in x direction and scroll (or auto) in the y direction. 因此,我想使其在x方向上可见,并在y方向上滚动(或自动)。

One possible solution would be to increase the width of #inner and make it equal to the image width, but I am not allowed to do that. 一种可能的解决方案是增加#inner的宽度,使其等于图像宽度,但是我不允许这样做。 I tried to insert a wrapper (#outter) but it didn't work. 我试图插入一个包装器(#outter),但是没有用。

Does anyone want how to solve the problem? 有人想要解决问题吗?

 #outter { width: 200px; height: 200px; overflow-y: scroll; } #inner { overflow-x: visible; width: 200px; height: 200px; } img { width: 400px; height: 400px } 
 <div id="outter"> <div id="inner"> <img src="http://www.w3schools.com/images/w3schools_green.jpg" alt="W3Schools.com"> </div> </div> 

You can use a wrapper element and float it to the left which will take it out of the normal document flow. 您可以使用包装器元素并将其浮动到左侧,这将使它脱离正常的文档流。 This floated element will then be as large as its content, which will get you the x-axis stretch/overflow but not the y-axis scroll. 然后,此浮动元素将与其内容一样大,这将使您获得x轴拉伸/溢出,但不能获得y轴滚动。 To get the y-axis scroll set a height and overflow controls on the floated wrapper. 要获取y轴滚动,请在浮动包装器上设置高度和溢出控件。

 /* Micro Clearfix - http://nicolasgallagher.com/micro-clearfix-hack/ */ .cf:before, .cf:after { content: " "; /* 1 */ display: table; /* 2 */ } .cf:after { clear: both; } .container { width: 200px; /* Following two properties, for demo, so you can see the container. */ min-height: 400px; background-color: pink; } .img-wrap { float: left; height: 200px; overflow-y: scroll; } img { width: 400px; height: 400px; } 
 <div class="container cf"> <div class="img-wrap"> <img src="http://www.w3schools.com/images/w3schools_green.jpg" alt="W3Schools.com"> </div> <p> Lorem ipsum dolor. </p> </div> 

You can set the image position to absolute, which would allow it to overflow its container: 您可以将图像位置设置为绝对位置,这将使其溢出容器:

 #outter { width: 200px; height: 200px; overflow-y: scroll; overflow-x: visible; } #inner { overflow-x: visible; width: 200px; height: 200px; } img { width: 400px; height: 400px; position: absolute; top: 0; left: 0; } 
 <div id="outter"> <div id="inner"> <img src="http://www.w3schools.com/images/w3schools_green.jpg" alt="W3Schools.com"> </div> </div> 

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

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