CSS多種佈局方式自我實現-水平佈局(二)
注:本文章參考自 How To Create a Horizontally Scrolling Site
一、概述
為了設計寬度自適應的水平佈局,原作者採用的CSS+JQ的方法,本文是對該方法的實踐,所有理論及操作援引自原文章。
如果設定一個很大的靜態寬度,不利於擴充套件;使用float無法解決行末塊元素自動換行的問題;直接使用table則非語義化(non-semantic);最後選擇使用JQ來為原HTML最後包裝table,既保證了原HTML的語義化,又實現了水平佈局。
二、HTML
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<article class="cell">this is article 1 this is article 1 this is article 1 this is article 1 this is article 1 this is article 1 this is article 1 this is article 1 this is article 1 this is article 1</article>
<article class="cell">this is article 2 this is article 2 this is article 2 this is article 2 this is article 2 this is article 2 this is article 2 this is article 2 this is article 2 this is article 2</article>
<article class="cell">this is article 3 this is article 3 this is article 3 this is article 3 this is article 3 this is article 3 this is article 3 this is article 3 this is article 3 this is article 3</article>
<article class="cell">this is article 4 this is article 4 this is article 4 this is article 4 this is article 4 this is article 4 this is article 4 this is article 4 this is article 4 this is article 4</article>
<article class="cell">this is article 5 this is article 5 this is article 5 this is article 5 this is article 5 this is article 5 this is article 5 this is article 5 this is article 5 this is article 5</article>
<article class="cell">this is article 6 this is article 6 this is article 6 this is article 6 this is article 6 this is article 6 this is article 6 this is article 6 this is article 6 this is article 6</article>
<article class="cell">this is article 7 this is article 7 this is article 7 this is article 7 this is article 7 this is article 7 this is article 7 this is article 7 this is article 7 this is article 7</article>
<article class="cell">this is article 8 this is article 8 this is article 8 this is article 8 this is article 8 this is article 8 this is article 8 this is article 8 this is article 8 this is article 8</article>
<article class="cell">this is article 9 this is article 9 this is article 9 this is article 9 this is article 9 this is article 9 this is article 9 this is article 9 this is article 9 this is article 9</article>
<article class="cell">this is article 10 this is article 10 this is article 10 this is article 10 this is article 10 this is article 10 this is article 10 this is article 10 this is article 10 this is article 10</article>
<article class="cell">this is article 11 this is article 11 this is article 11 this is article 11 this is article 11 this is article 11 this is article 11 this is article 11 this is article 11 this is article 11</article>
<article class="cell">this is article 12 this is article 12 this is article 12 this is article 12 this is article 12 this is article 12 this is article 12 this is article 12 this is article 12 this is article 12</article>
<article class="cell">this is article 13 this is article 13 this is article 13 this is article 13 this is article 13 this is article 13 this is article 13 this is article 13 this is article 13 this is article 13</article>
<article class="cell">this is article 14 this is article 14 this is article 14 this is article 14 this is article 14 this is article 14 this is article 14 this is article 14 this is article 14 this is article 14</article>
<article class="cell">this is article 15 this is article 15 this is article 15 this is article 15 this is article 15 this is article 15 this is article 15 this is article 15 this is article 15 this is article 15</article>
<article class="cell">this is article 16 this is article 16 this is article 16 this is article 16 this is article 16 this is article 16 this is article 16 this is article 16 this is article 16 this is article 16</article>
<article class="cell">this is article 17 this is article 17 this is article 17 this is article 17 this is article 17 this is article 17 this is article 17 this is article 17 this is article 17 this is article 17</article>
<article class="cell">this is article 18 this is article 18 this is article 18 this is article 18 this is article 18 this is article 18 this is article 18 this is article 18 this is article 18 this is article 18</article>
<article class="cell">this is article 19 this is article 19 this is article 19 this is article 19 this is article 19 this is article 19 this is article 19 this is article 19 this is article 19 this is article 19</article>
<article class="cell">this is article 20 this is article 20 this is article 20 this is article 20 this is article 20 this is article 20 this is article 20 this is article 20 this is article 20 this is article 20</article>
</body>
</html>
三、CSS程式碼
*{
padding:0;
margin:0;
}
body{
font-size:62.5%;
background-color: #f00;
}
.cell{
width:200px;
border:1px solid #0f0;
}
tr{
vertical-align:top;
}
四、JQ程式碼
$("#page-wrap").wrapInner("<table cell-spacing=30><tr>");
$(".cell").wrap("<td>");
五、結果展示
注意上圖下方有滾動條,同時此頁面豎直方向上可自由擴充套件,水平佈局完成。
相關文章
- 水平垂直居中佈局的多種實現方式
- css佈局-實現左中右佈局的5種方式CSS
- CSS 佈局之水平居中佈局CSS
- 佈局總結-水平居中佈局的實現
- 網頁佈局------幾種佈局方式網頁
- android筆記二(水平佈局與垂直佈局)Android筆記
- CSS佈局 --- 居中佈局CSS
- css佈局-float佈局CSS
- CSS佈局–聖盃佈局和雙飛翼佈局以及使用Flex實現聖盃佈局CSSFlex
- CSS+DIV佈局三種定位方式CSS
- 三種方法實現CSS三欄佈局CSS
- CSS 常見佈局方式CSS
- 細談CSS佈局方式CSS
- css經典佈局系列二——等分等高佈局CSS
- CSS佈局-各種居中CSS
- CSS 5種佈局方案CSS
- 使用 CSS columns 佈局來實現自動分組佈局CSS
- 三欄式佈局的幾種實現方式
- CSS佈局之三欄佈局CSS
- CSS佈局 --- 自適應佈局CSS
- CSS佈局 --- 等寬&等高佈局CSS
- 【css】佈局CSS
- css 佈局CSS
- CSS佈局CSS
- CSS佈局之水平居中和垂直居中CSS
- [css佈局1]不知寬高情況下,水平垂直居中的幾種方式CSS
- 如何用css實現"等高佈局"。CSS
- css佈局系列1——盒模型佈局CSS模型
- css各種佈局總結CSS
- Flutter佈局篇(1)–水平和垂直佈局詳解Flutter
- Flutter佈局篇(1)--水平和垂直佈局詳解Flutter
- CSS經典佈局——聖盃佈局與雙飛翼佈局CSS
- CSS 兩欄佈局和三欄佈局CSS
- CSS經典佈局之Sticky footer佈局CSS
- CSS Grid實現聖盃佈局CSS
- CSS實現三列DIV等高佈局CSS
- css flex佈局CSSFlex
- css佈局方法CSS