60 lines
1.3 KiB
HTML
60 lines
1.3 KiB
HTML
|
|
<!DOCTYPE html>
|
||
|
|
<html>
|
||
|
|
<head>
|
||
|
|
<style>
|
||
|
|
.container {
|
||
|
|
width: 1120px;
|
||
|
|
background-color: #fff;
|
||
|
|
padding: 20px 15px;
|
||
|
|
margin: 20px auto;
|
||
|
|
border: 1px solid #ddd;
|
||
|
|
}
|
||
|
|
|
||
|
|
.scroll-container {
|
||
|
|
width: 100%;
|
||
|
|
height: 300px;
|
||
|
|
overflow-x: auto;
|
||
|
|
overflow-y: hidden;
|
||
|
|
display: flex;
|
||
|
|
gap: 20px;
|
||
|
|
border: 2px solid red;
|
||
|
|
background: #f0f0f0;
|
||
|
|
}
|
||
|
|
|
||
|
|
.item {
|
||
|
|
flex: 0 0 164px;
|
||
|
|
width: 164px;
|
||
|
|
height: 260px;
|
||
|
|
background: #4096ff;
|
||
|
|
color: white;
|
||
|
|
display: flex;
|
||
|
|
align-items: center;
|
||
|
|
justify-content: center;
|
||
|
|
font-size: 20px;
|
||
|
|
border-radius: 8px;
|
||
|
|
}
|
||
|
|
</style>
|
||
|
|
</head>
|
||
|
|
<body>
|
||
|
|
<div class="container">
|
||
|
|
<h2>测试横向滚动</h2>
|
||
|
|
<div class="scroll-container" id="scrollContainer">
|
||
|
|
<!-- 将通过JS动态添加72个元素 -->
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<script>
|
||
|
|
const container = document.getElementById('scrollContainer');
|
||
|
|
for (let i = 1; i <= 72; i++) {
|
||
|
|
const item = document.createElement('div');
|
||
|
|
item.className = 'item';
|
||
|
|
item.textContent = `课程 ${i}`;
|
||
|
|
container.appendChild(item);
|
||
|
|
}
|
||
|
|
|
||
|
|
console.log('容器宽度:', container.offsetWidth);
|
||
|
|
console.log('内容宽度:', container.scrollWidth);
|
||
|
|
console.log('可滚动宽度:', container.scrollWidth - container.offsetWidth);
|
||
|
|
</script>
|
||
|
|
</body>
|
||
|
|
</html>
|