
父元素中子元素两行排列,超出部分隐藏
为了让父元素中的子元素两行排列,超出部分隐藏,可以使用以下方法:
<!-- 父元素 -->
<div id="container">
<!-- 子元素容器 -->
<div id="flex-container">
<!-- 子元素 -->
</div>
</div>
<!-- 省略号按钮 -->
<button id="more">...</button>#container {
width: 400px;
height: 200px;
border: 1px solid red;
overflow: hidden;
}
#flex-container {
display: flex;
flex-wrap: wrap;
}
.item {
width: 100px;
height: 100px;
background: #ccc;
}
#more {
display: none;
position: absolute;
top: 180px;
right: 10px;
}const moreButton = document.getElementById('more');
const container = document.getElementById('container');
const flexContainer = document.getElementById('flex-container');
moreButton.addEventListener('click', () => {
moreButton.style.display = 'none';
container.style.overflow = 'scroll';
});
// 当子元素超出父元素时显示省略号按钮
if (flexContainer.offsetWidth > container.offsetWidth) {
moreButton.style.display = 'block';
}以上就是如何实现父元素中子元素两行排列,超出部分隐藏?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号