简体   繁体   English

仅溢出-x隐藏

[英]Overflow-x hidden only

I've got the bx-slider that has overflow:hidden on its wrapper. 我的bx滑块已溢出:隐藏在其包装器中。 My layout dictates, that one element should break out of the box and lay above the top edge. 我的布局要求,一个元素应该打破常规,放在顶部边缘上方。

Does not sound hard at all - thats what overflow-y and x is for. 听起来一点也不难-那就是y和x的含义。 I thought. 我想。 But no matter what I do, once I set one of the values to hidden, the other (x or y) is hidden too. 但是无论做什么,一旦将其中一个值设置为hidden,另一个(x或y)也将被隐藏。

I've made a testcase which simulates the slider. 我做了一个模拟滑块的测试用例。 I want only the grey element to be displayed in full size out of the wrapper box. 我只希望灰色元素在包装盒中以完整尺寸显示。 The next elements should not be displayed until they flow into the viewport. 在下一个元素流入视口之前,不应显示它们。

 .wrapper { margin: 50px auto; width:400px; overflow-x:hidden; } .sliderContainer { width:1400px; } .sliderElement { width:400px; height:200px; background-color:red; display:inline-block; margin-right:50px; } .breakoutElement { width:50px; height:50px; background-color:grey; margin: -25px auto 0 auto; } 
 <div class="wrapper"> <div class="sliderContainer"> <div class="sliderElement"> <div class="breakoutElement"></div> </div> <div class="sliderElement"></div> <div class="sliderElement"></div> </div> </div> 

Instead of margin add padding to wrapper. 而不是保证金添加填充到包装。 Try this 尝试这个

 .wrapper { margin: auto auto; padding:50px 0px; width:400px; display:block; overflow-x:hidden; } .sliderContainer { width:1400px; } .sliderElement { width:400px; height:200px; background-color:red; display:inline-block; margin-right:50px; } .breakoutElement { width:50px; height:50px; background-color:grey; margin: -25px auto 0 auto; } 
 <div class="wrapper"> <div class="sliderContainer"> <div class="sliderElement"> <div class="breakoutElement"></div> </div> <div class="sliderElement"></div> <div class="sliderElement"></div> </div> </div> 

The reason for this behavior is according to the W3C spec : 出现这种现象的原因是根据W3C规范

[...] some combinations with 'visible' are not possible: if one is specified as 'visible' and the other is 'scroll' or 'auto', then 'visible' is set to 'auto'. [...]某些与“可见”的组合是不可能的:如果将一个指定为“可见”,而另一个指定为“滚动”或“自动”,则将“可见”设置为“自动”。

You simply can add a top margin to your slide elements and adjust their size accordingly: 您只需在幻灯片元素上添加上边距并相应地调整其大小即可:

.sliderElement {
  ...
  height: 175px;
  margin-top: 25px;
  ...
}

If you want your slide to be exactly 200px, simply adjust the wrappers height. 如果您希望幻灯片精确到200像素,只需调整包装器的高度即可。

 .wrapper { margin: 50px auto; width: 400px; overflow-x: hidden; } .sliderContainer { width: 1400px; } .sliderElement { width: 400px; height: 175px; background-color: red; display: inline-block; margin-right: 50px; margin-top: 25px; } .breakoutElement { width: 50px; height: 50px; background-color: grey; margin: -25px auto 0 auto; } 
 <div class="wrapper"> <div class="sliderContainer"> <div class="sliderElement"> <div class="breakoutElement"></div> </div> <div class="sliderElement"></div> <div class="sliderElement"></div> </div> </div> 

See this post for more information about the overflow problem. 请参阅此帖子以获取有关溢出问题的更多信息。

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

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