简体   繁体   English

CSS 溢出-x 隐藏和溢出-y 可见

[英]CSS overflow-x hidden and overflow-y visible

I have read this SO Post: css overflow-x visible and overflow-y hidden causes scroll bar.我已阅读此 SO 帖子: css 溢出-x 可见和溢出-y 隐藏导致滚动条。

Also I have gone through: http://www.brunildo.org/test/Overflowxy2.html我也经历过: http://www.brunildo.org/test/Overflowxy2.html

I want to achieve something as follows:我想实现以下目标:

溢出

When I tried using following code:当我尝试使用以下代码时:

overflow-x: hidden;
overflow-y: visible;

It shows something like following result:它显示类似于以下结果:
溢出 2
I dont want the scroll bar to appear.我不希望出现滚动条。

Does Jquery has any solution for it? Jquery 有解决方案吗?

You can do this with CSS like this: 您可以使用CSS执行此操作:

HTML: HTML:

<div class="wrapper">
    <div class="inner">
    </div>
</div>

CSS: CSS:

.wrapper{
    width: 400px;
    height: 300px;
}
.inner{
    max-width: 100%;
    overflow-x: hidden;
}

Now your .wrapper div will have overflow: visible; 现在你的.wrapper div会overflow: visible; but your .inner div will never overflow because it has a maximum width of 100% of the wrapper div. 但是你的.inner div永远不会溢出,因为它的最大宽度为包装div的100%。 Note that your wrapper must have an explicitly defined width. 请注意,您的包装器必须具有明确定义的宽度。

Here is a working jsFiddle 是一个有效的jsFiddle

See what are you trying to achieve is not possible in css and overflow won't let you achieve this. 看看你想要实现的是什么是不可能的css和overflow不会让你实现这一点。 Instead you can use jquery to get the output as you depicted in the posted picture/image. 相反,您可以使用jquery获取您在已发布的图片/图像中描述的输出。

I am not sure if you need something like this: 我不确定你是否需要这样的东西:

$('.horiz').width($('.container').width());

where .horiz is the horizontal bar and set the width of it to the width of the .container which holds the elements. 其中.horiz是水平条,并将其宽度设置为包含元素的.container的宽度。

HTML Markup HTML标记

<div class='container'>
    <div class='horiz'></div>
    <div class='vert'></div>
</div>

CSS: CSS:

 .container {
    width:320px;
    height:320px;
    border:solid 5px green;
 }
 .horiz{
    width:500px;
    height:30px;
    background:red;
 }
 .vert{
    width:30px;
    height:500px;
    background:yellow;
    position:absolute;
    left:0;
    top:30px;
 }

jQuery: jQuery的:

$(function(){
   $('.horiz').width($('.container').width());
});

and output of it: 和它的输出:

Check the Output 检查输出

CSS: CSS:

.class-div {
   overflow-x: clip;
   overflow-y: visible;
}

The thing with clip is, it restricts all scrolling, even programmatic ones.剪辑的问题是,它限制了所有滚动,甚至是编程滚动。

Refer: https://developer.mozilla.org/en-US/docs/Web/CSS/overflow参考: https://developer.mozilla.org/en-US/docs/Web/CSS/overflow

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

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