10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

連続するリストを横並びに等分表示する...レスポンシブへの足がかり

Last updated at Posted at 2015-06-13

簡単なCSSで連続するリストを横並びに等分表示してみた。プログラマー未満人にはレスポンシブへの足がかりにならないかと...

<div id="item-list">
<ul class="cols-3">
<li>商品01</li>
<li>商品02</li>
<li>商品03</li>
<li>商品04</li>
<li>商品05</li>
<li>商品06</li>
</ul>
</div>
/* 便宜的に...すべての余白を0に、box-sizing を border-boxに
* {  
  margin:0;
  padding:0;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  -ms-box-sizing: border-box;
  box-sizing: border-box;
}

#item-list {
  background:#ccc;
  padding:20px 10px 0 10px;
  margin-bottom:20px;
}

#item-list ul{
  margin-left:-20px;/1カラムのpadding分マイナスマージン*/
  overflow:hidden;
  background-color:transparent;
}

#item-list ul li {
  list-style-type:none;
  float:left; /*floatで横並びに*/
  padding-left:20px;/*カラム間のガター*/
  margin-bottom:20px;
  text-align:center;
}

ul.cols-1 li {width: 100%;}
ul.cols-2 li {width: 50%;}
ul.cols-3 li {width: 33.33333%;}
ul.cols-4 li {width: 25%;}
ul.cols-5 li {width: 20%;}
ul.cols-6 li {width: 16.66666%;}
ul.cols-7 li {width: 14.28571%;}
ul.cols-8 li {width: 12.5%;}

.inner{ /*カラムの内側*/
  margin:0;
  height:100%;
  background:white;
}

@media only screen and (max-width: 767px) {
  ul.cols-4 li,ul.cols-5 li,ul.cols-6 li,ul.cols-7 li,ul.cols-8 li{
	  width: 33%;/*4列以上は3列に*/
  }
  ul.cols-3 li{
	  width:50%;/*3列は2列に*/
  } 
}

@media only screen and (max-width: 479px) {
  ul[class*='cols-'] > li{
	  width: 100%;/*すべてを1列に*/
  }
}

<script type = "text/javascript" src = "jquery-1.10.2.min.js"></script>
<script type = "text/javascript" src = "jquery.matchHeight.js"></script>
<script type = "text/javascript">
$(document).ready(function() {
  $("#item-list ul li").wrapInner("<div class='inner'></div>");
  $("#item-list ul li >.inner").matchHeight();
});
</script>

サンプル
http://qitailang.small.jp/misc/equal_cell/sample2.html

10
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?