首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

CSS max-height和overflow auto始终显示垂直滚动

CSS max-height 和 overflow auto 始终显示垂直滚动

max-height 属性用于限制元素的最大高度。当内容超过容器的 height 时,它会自动显示垂直滚动条。而 overflow 属性用于控制元素在内容溢出时如何显示滚动条。

overflow 属性中,auto 意味着如果内容高度超出容器的 height,则显示垂直滚动条。而 scroll 属性表示始终显示滚动条。

示例:

代码语言:html
复制
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Example</title>
    <style>
        .container {
            max-height: 200px;
            overflow-y: auto;
        }
    </style>
</head>
<body>
    <div class="container">
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam scelerisque libero id velit laoreet fringilla...</p>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam scelerisque libero id velit laoreet fringilla...</p>
    </div>
</body>
</html>

在这个例子中,.container 类的元素具有固定的 max-height 为 200px,当内容高度超出时,将自动显示垂直滚动条。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

没有搜到相关的结果

领券