予め設定された数の列に依存しないグリッドを作成しようとしています。私は状況を表示するために、少量のサンプルを作成しました:グリッドとの援助:nth-child(an + b)
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Grid in HTML5 and CSS3</title>
<style>
* {margin:0;padding:0;}
.row {display:block;position:relative;clear:both;}
.row>* {display:block;position:relative;clear:both;float:left;clear:none;width:100%;}
.row>*:empty {width:0px;}
/* one column in the row */
.row>:nth-last-child(1):nth-child(1) {width:100%;}
/* two columns in the row */
.row>:nth-last-child(2):nth-child(1) {width:50%;}
.row>:nth-last-child(1):nth-child(2) {width:50%;}
/* three columns in the row */
.row>:nth-last-child(3):nth-child(1) {width:33.33%;}
.row>:nth-last-child(2):nth-child(2) {width:33.33%;}
.row>:nth-last-child(1):nth-child(3) {width:33.34%;}
.row>:empty:nth-last-child(3):nth-child(1)+:not(:empty) {width:66.66%;}
.row>:empty:nth-last-child(2):nth-child(2)+:not(:empty) {width:66.67%;}
article {margin:.5em;border:1px solid green;border-radius:.3em;padding:.5em; }
</style>
</head>
<body>
<section class="row">
<div>
<article>
<p>This row has only one child.</p>
</article>
</div>
</section>
<section class="row">
<div>
<article>
<p>This row has two children</p>
</article>
</div>
<div>
<article>
<p>This is the second child</p>
</article>
</div>
</section>
<section class="row">
<div>
<article>
<p>
This row has three children
</p>
</article>
</div>
<div>
<article>
<p>So this is col 2 of 3</p>
</article>
</div>
<div>
<article>
<p>And this is col 3 of 3.</p>
</article>
</div>
</section>
<section class="row">
<div></div>
<div>
<article>
<p>The first child of this row is empty so spanned with the second</p>
</article>
</div>
<div>
<article>
<p>This is the second column</p>
</article>
</div>
</section>
<section class="row">
<div>
<article>
<p>This is the first column</p>
</article>
</div>
<div></div>
<div>
<article>
<p>The second and third column are spanned</p>
</article>
</div>
</section>
</body>
</html>
私はより大きなサンプル置く - 私の問題は、今あなたがしたい場合ということです
http://jsfiddle.net/jordenvanforeest/MDv32/
でjsfiddleに - より詳細に問題を説明しますこのグリッドは3つ以上の列に対応するため、CSSサイズは指数関数的に大きくなります。だから私は他の解決策を探しています。
.row>:nth-last-child(an+b):nth-child(cn+d) {}
私の計算能力は少し錆びており、正しく動作するようにはできません。 ヘルプが大歓迎です。
更新は、CSSがはるかに小さく答えを提供します。このfiddleは、彼が提案した改良版です。
他の提案は、まだ歓迎されています。私の12門のグリッドグリッドは、スパニングのためにまだ30Kが必要です。
1:このようなクールな実験! –
はい、お手伝いできますか? –
これは興味深い考えです。現在の実装では空のdivが必要なだけの欠点がありますが、これが本番環境でどのように使用されていると思いますか? – Mindthetic