overflow妙用--去除默认滚动条,内容仍可滚动

在开发中我们往往要去除默认滚动条,但是其在竖直方向的滚动效果仍然需要。

<div id="parent">
            <div id="child">
                <h1>文本区</h1>
                <h1>文本区</h1>
                <h1>文本区</h1>
            </div> 
        </div>
#parent {
        width: 100px;
        height: 100px;
        border: 1px solid green;
        overflow: hidden;
    }
    #child {
        width: 150px;
        height: 100px;
        overflow-x: hidden;
    }

其中父级div的width为100px,子div的宽度为150px,就是说在水平方向,子div是有溢出的。

当我们给子div添加一个overflow-x:hidden的属性及属性值后,便将子div的溢出部分隐藏掉。效果达成。

原文地址:https://www.cnblogs.com/lodadssd/p/7693881.html