2010-11-24 74 views

回答

4

我看到你正在嘗試做的,如果你是浮動的貴麗的,你會發現他們被他們的容器包裹並溢出到下一行。要解決這個問題,你需要使用下面的代碼:

#container{ 
overflow:hidden; 
white-space: nowrap;/*prevents wrapping*/ 
} 

li{ 
display:inline-block; 
zoom:1; *display: inline;/*IE7 Fix for inline-block*/ 
} 

希望這有助於隊友!

W.

2
ul { width: 800px; overflow: hidden; } 
-2
html,body {width:100%;height:100%;border:0;margin:0;} 
ul {width:100%; position:relative;} 
1

正如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">&lt;</button> 
 
    <button id="scroll_right">&gt;</button> 
 
</div>

在這裏,我用兩個按鈕與IDS scroll_left和左,右分別被用於滾動scroll_right。

相關問題