Reputation: 433
I'm using latest Bootstrap 3.0 RC1 and trying to build an image overview with responsiveness and multiple break points when the images becomes too small (like seen on Dribbble).
Issues:
I hope someone can help me out, I'm a beginner to building responsive stuff..
Best regards
Link to jsfiddle:
http://jsfiddle.net/6dckB/ (your browser must be wide to see the effects)
HTML:
<div class="container">
<ul class="row-fluid">
<li class="group">
<div class="img-thumbnail">
<a href="#">
<img src="http://placehold.it/350x150" style="width:100%;">
</a>
</div>
</li>
<li class="group">
<div class="img-thumbnail">
<a href="#">
<img src="http://placehold.it/350x150" style="width:100%;">
</a>
</div>
</li>
<li class="group">
<div class="img-thumbnail">
<a href="#">
<img src="http://placehold.it/350x150" style="width:100%;">
</a>
</div>
</li>
<li class="group">
<div class="img-thumbnail">
<a href="#">
<img src="http://placehold.it/350x150" style="width:100%;">
</a>
</div>
</li>
<li class="group">
<div class="img-thumbnail">
<a href="#">
<img src="http://placehold.it/350x150" style="width:100%;">
</a>
</div>
</li>
<li class="group">
<div class="img-thumbnail">
<a href="#">
<img src="http://placehold.it/350x150" style="width:100%;">
</a>
</div>
</li>
<li class="group">
<div class="img-thumbnail">
<a href="#">
<img src="http://placehold.it/350x150" style="width:100%;">
</a>
</div>
</li>
<li class="group">
<div class="img-thumbnail">
<a href="#">
<img src="http://placehold.it/350x150" style="width:100%;">
</a>
</div>
</li>
</ul>
</div>
CSS:
.row-fluid {
padding-left: 0;
list-style: none;
}
.row-fluid:before,
.row-fluid:after {
content: " ";
/* 1 */
display: table;
/* 2 */
}
.row-fluid:after {
clear: both;
}
.row-fluid:before,
.row-fluid:after {
content: " ";
/* 1 */
display: table;
/* 2 */
}
.row-fluid:after {
clear: both;
}
@media (min-width: 768px) {
.row-fluid {
margin-left: -10px;
margin-right: -10px;
}
}
.row-fluid .row {
margin-left: -10px;
margin-right: -10px;
}
.row-fluid .group {
position: relative;
min-height: 1px;
padding-left: 10px;
padding-right: 10px;
float: left;
width: 50%;
margin-bottom: 20px;
}
@media (max-width: 400px) {
.row-fluid .group {
position: relative;
min-height: 1px;
padding-left: 10px;
padding-right: 10px;
float: left;
width: 100%;
}
}
@media (min-width: 768px) and (max-width: 991px) {
.row-fluid .group {
position: relative;
min-height: 1px;
padding-left: 10px;
padding-right: 10px;
float: left;
width: 33.33333333333333%;
}
}
@media (min-width: 992px) {
.row-fluid .group {
position: relative;
min-height: 1px;
padding-left: 10px;
padding-right: 10px;
float: left;
width: 25%;
}
}
Upvotes: 5
Views: 13502
Reputation: 972
Just changed some css and it works. See this fiddle: http://jsfiddle.net/J3F99/
Well, the major changes being:
box-sizing: border-box
to .group so that the % width is inclusive of the padding(10px).display: inline-block
to and removed the float: left
in .group, and text-align: center
to .row-fluid so that the .group elements are centre aligned.max-width: 350px
and max-height: 150px
to .groupThats it. It works well in chrome. I din't test in other browsers. Use full bootstrap while testing.
The main problem here is the padding, given in pixels. To ensure clean fluid layout you should use % instead if pixels. And for that you have to use margin rather than padding for .group. Because, margin in % depends on the container width.
For example, 4 .group elements with width 20% and margin-right and margin-left 2.5% will fit exactly whithin the container(.row-fluid here) without leaving out a single pixel.
4*20 + 4*2.5*2 = 100%
I recommend you to go with that method. See @Bharat Parmar's answer for that.
Upvotes: 1
Reputation: 802
Check this demo: http://depotwebdesigner.com/responsive/
HTML:
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Responsive Image</a>
<div class="nav-collapse collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div>
</div>
</div>
<!-- Responsive Image -->
<div class="container">
<div class="starter-template">
<ul>
<li><img src="http://dribbble.s3.amazonaws.com/users/31348/screenshots/1185698/slightly_stoopid_teaser.jpg" alt=""></li>
<li><img src="http://dribbble.s3.amazonaws.com/users/12/screenshots/1185739/google_chromescreensnapz001_teaser.png" alt=""></li>
<li><img src="http://dribbble.s3.amazonaws.com/users/22225/screenshots/1185692/cooper_workshop_teaser.jpg" alt=""></li>
<li><img src="http://dribbble.s3.amazonaws.com/users/565/screenshots/1186432/kreyos_sport_mode_1x.jpg" alt=""></li>
<li><img src="http://dribbble.s3.amazonaws.com/users/6014/screenshots/1186351/oliver.jpg" alt=""></li>
<li><img src="http://dribbble.s3.amazonaws.com/users/93631/screenshots/1185715/drip-lion.jpg" alt=""></li>
<li><img src="http://dribbble.s3.amazonaws.com/users/104062/screenshots/1186702/pw_1x.png" alt=""></li>
<li><img src="http://dribbble.s3.amazonaws.com/users/7528/screenshots/1186361/genesisproject_1x.jpg" alt=""></li>
<li><img src="http://dribbble.s3.amazonaws.com/users/2896/screenshots/1186026/free_to_be_1x.png" alt=""></li>
<li><img src="http://dribbble.s3.amazonaws.com/users/2559/screenshots/1185760/screen_shot_2013-08-06_at_10.32.27_am.png" alt=""></li>
<li><img src="http://dribbble.s3.amazonaws.com/users/4737/screenshots/1178958/untitled-1_1x.png" alt=""></li>
<li><img src="http://dribbble.s3.amazonaws.com/users/4737/screenshots/1186176/site_1x.jpg" alt=""></li>
</ul>
</div>
</div>
CSS:
body {
padding-top: 50px;
background: #f8f8f8;
}
img {
max-width: 100%;
max-height: 150px;
}
ul{
padding: 0;
}
.content {
width: 970px;
margin: 0 auto;
}
.starter-template {
margin-top: 10px;
}
.starter-template li {
width: 20%;
position: relative;
float:left;
list-style: none;
background: #fff;
padding: 10px;
margin-bottom: 20px;
margin-right: 20px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
-webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.07);
-moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.07);
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.07);
}
@media (max-width: 315px) {
.starter-template li {
margin: 0 0 3px 3px !important;
}
}
@media (max-width: 735px) and (min-width: 450px) {
.starter-template li {
width: 30%;
margin-right: 0;
margin-left: 15px;
}
}
@media (max-width: 450px) {
.starter-template li {
width: 45%;
margin-right: 20px;
margin-left: 10px;
}
.starter-template li:nth-child(2n){
margin-left: 0;
margin-right: 0;
}
}
jsfiddle: http://jsfiddle.net/VJBjL/5/
Upvotes: 0
Reputation: 362360
It doesn't appear that you are using Bootstrap 3 RC1. The link in your fiddle is broken. Bootstrap RC1 doesn't have .row-fluid
anymore.
You could just simplify everything by letting the responsive features in 3 do the work for you. BS3 now has 3 grid sizes -- tiny, small and large that are used to manipulate display on different devices / widths. You could do something like this..
<div class="row">
<div class="col-lg-3 col-sm-4 col-6">
<a href="#" class="thumbnail">
<img src="http://placehold.it/350x150" class="img-responsive">
</a>
</div>
<div class="col-lg-3 col-sm-4 col-6">
<a href="#" class="thumbnail">
<img src="http://placehold.it/350x150" class="img-responsive">
</a>
</div>
...
</div>
That will get you..
col-lg-3
)col-sm-4
)col-6
)Demo: http://bootply.com/70929
Upvotes: 12