小提琴:http://jsfiddle.net/WsYw8/
演示什麼即時通訊的談論:http://netkoder.dk/test/test0251.html正確的方法,使元素與水平滾動
HTML
<div class="spotlysholderholder baggrundlinear1 bordertype1 borderradius5px">
<div class="spotlysholderholderb" style="width: 3200px;">
<a href="/" class="spotlysholder background_color_2 fontsize_xsmall fontfamily_1 bordertype1 borderradius5px"><img src="test0251_filer/billed0001.png" alt="Notepad++" class="spotlysbillede"><span class="">NOTEPAD++</span>er et tekstredigeringsprogram du kan bruge til at skrive dine koder</a>
<a href="/" class="spotlysholder background_color_2 fontsize_xsmall fontfamily_1 bordertype1 borderradius5px"><img src="test0251_filer/billed0001.png" alt="Notepad++" class="spotlysbillede"><span class="">NOTEPAD++</span>er et tekstredigeringsprogram du kan bruge til at skrive dine koder</a>
<a href="/" class="spotlysholder background_color_2 fontsize_xsmall fontfamily_1 bordertype1 borderradius5px"><img src="test0251_filer/billed0001.png" alt="Notepad++" class="spotlysbillede"><span class="">NOTEPAD++</span>er et tekstredigeringsprogram du kan bruge til at skrive dine koder</a>
<a href="/" class="spotlysholder background_color_2 fontsize_xsmall fontfamily_1 bordertype1 borderradius5px"><img src="test0251_filer/billed0001.png" alt="Notepad++" class="spotlysbillede"><span class="">NOTEPAD++</span>er et tekstredigeringsprogram du kan bruge til at skrive dine koder</a>
<a href="/" class="spotlysholder background_color_2 fontsize_xsmall fontfamily_1 bordertype1 borderradius5px"><img src="test0251_filer/billed0001.png" alt="Notepad++" class="spotlysbillede"><span class="">NOTEPAD++</span>er et tekstredigeringsprogram du kan bruge til at skrive dine koder</a>
<a href="/" class="spotlysholder background_color_2 fontsize_xsmall fontfamily_1 bordertype1 borderradius5px"><img src="test0251_filer/billed0001.png" alt="Notepad++" class="spotlysbillede"><span class="">NOTEPAD++</span>er et tekstredigeringsprogram du kan bruge til at skrive dine koder</a>
<a href="/" class="spotlysholder background_color_2 fontsize_xsmall fontfamily_1 bordertype1 borderradius5px"><img src="test0251_filer/billed0001.png" alt="Notepad++" class="spotlysbillede"><span class="">NOTEPAD++</span>er et tekstredigeringsprogram du kan bruge til at skrive dine koder</a>
<a href="/" class="spotlysholder background_color_2 fontsize_xsmall fontfamily_1 bordertype1 borderradius5px"><img src="test0251_filer/billed0001.png" alt="Notepad++" class="spotlysbillede"><span class="">NOTEPAD++</span>er et tekstredigeringsprogram du kan bruge til at skrive dine koder</a>
<a href="/" class="spotlysholder background_color_2 fontsize_xsmall fontfamily_1 bordertype1 borderradius5px"><img src="test0251_filer/billed0001.png" alt="Notepad++" class="spotlysbillede"><span class="">NOTEPAD++</span>er et tekstredigeringsprogram du kan bruge til at skrive dine koder</a>
<a href="/" class="spotlysholder background_color_2 fontsize_xsmall fontfamily_1 bordertype1 borderradius5px"><img src="test0251_filer/billed0001.png" alt="Notepad++" class="spotlysbillede"><span class="">NOTEPAD++</span>er et tekstredigeringsprogram du kan bruge til at skrive dine koder</a>
<a href="/" class="spotlysholder background_color_2 fontsize_xsmall fontfamily_1 bordertype1 borderradius5px"><img src="test0251_filer/billed0001.png" alt="Notepad++" class="spotlysbillede"><span class="">NOTEPAD++</span>er et tekstredigeringsprogram du kan bruge til at skrive dine koder</a>
<a href="/" class="spotlysholder background_color_2 fontsize_xsmall fontfamily_1 bordertype1 borderradius5px"><img src="test0251_filer/billed0001.png" alt="Notepad++" class="spotlysbillede"><span class="">NOTEPAD++</span>er et tekstredigeringsprogram du kan bruge til at skrive dine koder</a>
<a href="/" class="spotlysholder background_color_2 fontsize_xsmall fontfamily_1 bordertype1 borderradius5px"><img src="test0251_filer/billed0001.png" alt="Notepad++" class="spotlysbillede"><span class="">NOTEPAD++</span>er et tekstredigeringsprogram du kan bruge til at skrive dine koder</a>
<a href="/" class="spotlysholder background_color_2 fontsize_xsmall fontfamily_1 bordertype1 borderradius5px"><img src="test0251_filer/billed0001.png" alt="Notepad++" class="spotlysbillede"><span class="">NOTEPAD++</span>er et tekstredigeringsprogram du kan bruge til at skrive dine koder</a>
<a href="/" class="spotlysholder background_color_2 fontsize_xsmall fontfamily_1 bordertype1 borderradius5px"><img src="test0251_filer/billed0001.png" alt="Notepad++" class="spotlysbillede"><span class="">NOTEPAD++</span>er et tekstredigeringsprogram du kan bruge til at skrive dine koder</a>
<a href="/" class="spotlysholder background_color_2 fontsize_xsmall fontfamily_1 bordertype1 borderradius5px"><img src="test0251_filer/billed0001.png" alt="Notepad++" class="spotlysbillede"><span class="">NOTEPAD++</span>er et tekstredigeringsprogram du kan bruge til at skrive dine koder</a>
<div class="clearboth"></div>
</div>
</div>
CSS
.spotlysholderholder {
overflow-x: auto;
}
.spotlysholderholderb {
padding: 4px;
margin: 0 auto;
/* width: 800px;*/
}
.spotlysholderholderb a,
.spotlysholderholderb a:visited,
.spotlysholderholderb a:active {
color: #222;
}
.spotlysholder {
text-align: center;
width: 180px;
float: left;
margin: 4px;
padding: 5px;
text-decoration: none;
/* for at undgå at langeordudenmellem ikke går ud over kanten */
overflow: hidden;
text-overflow: ellipsis;
}
.spotlysholder:hover {
background: #ccc;
text-decoration: underline;
border-color: black;
}
.spotlyoverskrift {
display: block;
font-weight: bold;
color: maroon;
}
.spotlysbillede {
margin: 5px auto;
vertical-align: bottom;
}
.baggrundlinear1 {
background-color: #445263; /* fallback */
box-shadow: inset 0 2px 2px rgba(255, 255, 255, 0.4), inset -2px 0 2px rgba(0, 0, 0, 0.2), inset 0 -2px 2px rgba(0, 0, 0, 0.2), inset 2px 0 2px rgba(255, 255, 255, 0.4);
}
.bordertype1 {
border: 1px solid #7c7c7c; /* fallback farve når rgba ikke virker */
border: 1px solid rgba(0,0,0,0.5);
border: 1px solid rgba(0,0,0,0.25);
}
.background_color_2 {
background-color: #ddd; /* fallback */
}
.borderradius5px {
border-radius: 5px;
}
.spotlysbillede {
margin: 5px auto;
vertical-align: bottom;
}
.clearboth {
clear: both;
}
我有一個16個框的滾動元素。
每個盒子都是200像素寬,包括填充。
爲了讓他們都在同一行我做父容器elemenet 16 * 200像素寬。如果有16個盒子,我會把它做成3200px寬。
我有2個問題。
1:我怎樣才能避免設置父容器元素的寬度,並仍然在同一行上的所有框?
2:當我使用瀏覽器進行縮小時,最後一個框跳下2行。
是否使用任何服務器端腳本添加的盒裝來劃分的隨機數? – Zword
是的,我希望能夠改變框的數量,而不必設置寬度。現在我計算X * 200 serverside的寬度,但如果可能的話,我不想這樣做。 – scootergrisen