正如wilsonpage說,
- 溢出:隱藏; (用於隱藏容器外的內容)
- white-space:nowrap; (用於使內容在同一行上繼續,直到
<br>
)
用於實現您想要的功能。
以及你必須使用一些jquery爲了使元素滾動按鈕點擊。
相同的代碼已包含在下面的代碼片段中。
$('#scroll_left').click(function() {
var leftPos = $('div.list_Items').scrollLeft();
console.log(leftPos);
$("div.list_Items").animate({
scrollLeft: leftPos - 230
}, 800);
});
$('#scroll_right').click(function() {
var leftPos = $('div.list_Items').scrollLeft();
console.log(leftPos);
$("div.list_Items").animate({
scrollLeft: leftPos + 230
}, 800);
});
.container {
padding-bottom:5px;
border-bottom: 1px solid black;
width:310px;
}
.list_Items {
width:230px;
float:left;
overflow:hidden;
margin-right:20px;
}
.tabs {
margin: 0 0 10px;
padding: 0 0 4px;
cursor: pointer;
white-space: nowrap;
}
.tabs li {
background: #D1E2F3;
border: 1px solid #fff;
display: inline-block;
font-family: arial;
font-size: 11px;
color: #227799;
padding: 3px 10px;
}
.tabs li a, .tabs li a:hover {
text-decoration: none !important;
font-size: 11px;
color: #666;
}
.tabs li.title {
background: none;
border: 0;
}
.tabs li.active {
background: #092B44;
border: 1px solid #092B44;
color: white;
}
.tabs li.active a {
color: #fff !important
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<div class="list_Items">
<!-- The width is limited -->
<ul class="tabs">
<li class="active">List-Item-1</li>
<li>List-Item-2</li>
<li>List-Item-3</li>
<li>List-Item-4</li>
<li>List-Item-5</li>
<li>List-Item-6</li>
<li>List-Item-7</li>
<li>List-Item-8</li>
<li>List-Item-9</li>
<li>List-Item-10</li>
</ul>
</div>
<button id="scroll_left"><</button>
<button id="scroll_right">></button>
</div>
在這裏,我用兩個按鈕與IDS scroll_left和左,右分別被用於滾動scroll_right。