html Bootstrap块网格布局

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html Bootstrap块网格布局相关的知识,希望对你有一定的参考价值。

[class*="block-grid-"] {
  display: block;
  
  padding: 0;
  @extend .grid-row;
}
 
.block-grid-item {
  display: inline;
  margin: 0;
  padding: ($grid-gutter-width/2);
	padding-left:0; 
  height: auto;
  float: left;
  
}
 
@mixin block-grid ($per-row) {
  & > .block-grid-item {
    width: (100%/$per-row);
 
    $nth-equation: #{$per-row}n+'+'+1;
    &:nth-of-type(n) { clear: none; }
    &:nth-of-type(#{$nth-equation}) { clear: both; }
  }
}
 
@mixin block-grids($size) {
  .block-grid-#{$size}-1  { @include block-grid(1);  }
  .block-grid-#{$size}-2  { @include block-grid(2);  }
  .block-grid-#{$size}-3  { @include block-grid(3);  }
  .block-grid-#{$size}-4  { @include block-grid(4);  }
  .block-grid-#{$size}-5  { @include block-grid(5);  }
  .block-grid-#{$size}-6  { @include block-grid(6);  }
  .block-grid-#{$size}-7  { @include block-grid(7);  }
  .block-grid-#{$size}-8  { @include block-grid(8);  }
  .block-grid-#{$size}-9  { @include block-grid(9);  }
  .block-grid-#{$size}-10 { @include block-grid(10); }
  .block-grid-#{$size}-11 { @include block-grid(11); }
  .block-grid-#{$size}-12 { @include block-grid(12); }
}
 
@include block-grids(xs); 
@media (min-width: $screen-sm-min) { @include block-grids(sm) }
@media (min-width: $screen-md-min) { @include block-grids(md) }
@media (min-width: $screen-lg-min) { @include block-grids(lg) }




//EXAMPLE USAGE

.block-grid-example{
	@extend .grid-row;
	@include block-grid(4);
	.block-grid-example-item{
		@extend .block-grid-item;
		position:relative;
	}

	@media (max-width: 715px){ 
		@include block-grid(2);
	}
	@media (max-width: 427px){ 
		@include block-grid(1);
	}
}
<div class="block-grid-example">
	<div class="block-grid-example-item">
		<img src="http://placehold.it/350x150">
	</div>
	<div class="block-grid-example-item">
		<img src="http://placehold.it/350x150">
	</div>
	<div class="block-grid-example-item">
		<img src="http://placehold.it/350x150">
	</div>
	<div class="block-grid-example-item">
		<img src="http://placehold.it/350x150">
	</div>
	<div class="block-grid-example-item">
		<img src="http://placehold.it/350x150">
	</div>
	<div class="block-grid-example-item">
		<img src="http://placehold.it/350x150">
	</div>
	<div class="block-grid-example-item">
		<img src="http://placehold.it/350x150">
	</div>
	<div class="block-grid-example-item">
		<img src="http://placehold.it/350x150">
	</div>
</div>

以上是关于html Bootstrap块网格布局的主要内容,如果未能解决你的问题,请参考以下文章

Bootstrap 3 流体网格布局问题?

bootstrap学习总结-02 网格布局

Bootstrap 4.0 网格系统布局不起作用

从 Bootstrap 3 迁移的 Bootstrap 4 网格布局问题

Bootstrap 4 - 结合网格系统的砌体布局(二、三、四和六列布局)[重复]

使用 flexbox 网格的 Bootstrap 4 砌体布局