Bootstrap image resizing for different screens - html

I have found a few similar questions but none of them answer exactly what I am hoping for.
I am building a portfolio site,
I am using bootstrap 3 and would like to have my div box have three images across when on small/medium/large but only two across when on extra-small.
I have the images html housed in div liked this
<div class="row" id="artpieces">
<div class="col-md-12 col-xs-12">
CODE FOR THE IMAGES
</div>
</div>
I have been achieving my goal of three images so far with
#artpieces .col-md-12 img {
width: 33%;
}
I have been trying to do something like
#artpieces .col-xs-12 img {
width : 49.5%;
}
but it doesn't make the switch when it gets small. I feel like I am making a very dumb mistake, but can't catch it. (I have tested the %s using a more brute force way one at a time, and they do show up how I want, but it doesn't work when I try both).
PS: this is my first time building a website and I am learning/practicing HTML and CSS. Most of it has been going smooth, but this is the first real issue I haven't been able to solve.

Why not place each image in a div with the classes col-md-12 col-xs-12?
HTML:
<div class="container">
<div class="row" id="artpieces">
<div class="col-md-12 col-xs-12">
<div class="col-md-4 col-xs-6">
<img src="//placehold.it/300x350" class="img-responsive">
</div>
<div class="col-md-4 col-xs-6">
<img src="//placehold.it/300x350" class="img-responsive">
</div>
<div class="col-md-4 col-xs-6">
<img src="//placehold.it/300x350" class="img-responsive">
</div>
<div class="col-md-4 col-xs-6">
<img src="//placehold.it/300x350" class="img-responsive">
</div>
<div class="col-md-4 col-xs-6">
<img src="//placehold.it/300x350" class="img-responsive">
</div>
<div class="col-md-4 col-xs-6">
<img src="//placehold.it/300x350" class="img-responsive">
</div>
</div>
</div>
</div>
Live Demo: http://www.bootply.com/iy3Js8LV5X

Related

How to make stretchable bootstrap div according to mobile, tablet, desktop

I am learning bootstrap framework and found it very interesting. I have seen a website that is working awesome on mobile, tablet and laptop at the same time. I saw four div in the page in one line and when a user stretch the page, it hides the two div and make it nice view able on the tablet and when i stretch it more according to the mobile size it hides the 3 div and display only one with nice css effects.
Please have a look on the following three images and see the desired effects that i need to achieve.
I just need to implement the same using bootstrap. Please anyone guide or share the sample code to understand. Many thanks in advance.
You can do something like this to achieve the desired results. Bootstrap gives you control on how your div block will behave on different devices or screen sizes.
Check out the code below.
<div class="contaniner">
<div class="row">
<div class="col-md-12">
<div class="col-md-3 col-sm-6 col-xs-12">
<div class="col-md-12 col-sm-4 col-xs-6">
<img src="http://www.planwallpaper.com/static/images/i-should-buy-a-boat.jpg" class="img-responsive"/>
</div>
<div class="col-md-12 col-sm-8 col-xs-6">
<h4 class="h4"> Some text Here...</h4>
<p> Some more text Here...</p>
</div>
</div>
<div class="col-md-3 col-sm-6 col-xs-12">
<div class="col-md-12 col-sm-4 col-xs-6">
<img src="http://www.planwallpaper.com/static/images/i-should-buy-a-boat.jpg" class="img-responsive"/>
</div>
<div class="col-md-12 col-sm-8 col-xs-6">
<h4 class="h4"> Some text Here...</h4>
<p> Some more text Here...</p>
</div>
</div>
<div class="col-md-3 col-sm-6 col-xs-12">
<div class="col-md-12 col-sm-4 col-xs-6">
<img src="http://www.planwallpaper.com/static/images/i-should-buy-a-boat.jpg" class="img-responsive"/>
</div>
<div class="col-md-12 col-sm-8 col-xs-6">
<h4 class="h4"> Some text Here...</h4>
<p> Some more text Here...</p>
</div>
</div>
<div class="col-md-3 col-sm-6 col-xs-12">
<div class="col-md-12 col-sm-4 col-xs-6">
<img src="http://www.planwallpaper.com/static/images/i-should-buy-a-boat.jpg" class="img-responsive"/>
</div>
<div class="col-md-12 col-sm-8 col-xs-6">
<h4 class="h4"> Some text Here...</h4>
<p> Some more text Here...</p>
</div>
</div>
</div>
</div>
</div>

Image grid (Bootstrap) and compensating for margins

I have the following grid - http://codepen.io/vmpen/pen/GqrXQz where aspect ratios must be preserved, whilst being responsive. With no padding
the grid behaves correctly.
<div class="container">
<div class="row-fluid">
<div class="col-xs-3 grid-sizer"></div>
<div class="text-center feature feature--full col-xs-12">
<div class="img-wrapper"><img class="img-responsive" src="https://placehold.it/1080x270"></div>
</div>
<div class="text-center feature feature--width2 col-md-6 col-sm-12">
<div class="img-wrapper height2"><img class="img-responsive" src="https://placehold.it/540x540"></div>
</div>
<div class="col-md-3 col-sm-6 feature">
<div class="img-wrapper"><img class="img-responsive" src="https://placehold.it/270x270"></div>
</div>
<div class="col-md-3 col-sm-6 feature">
<div class="img-wrapper"><img class="img-responsive" src="https://placehold.it/270x270"></div>
</div>
<div class="col-md-3 col-sm-6 feature">
<div class="img-wrapper"><img class="img-responsive" src="https://placehold.it/270x270"></div>
</div>
<div class="col-md-3 col-sm-6 feature">
<div class="img-wrapper"><img class="img-responsive" src="https://placehold.it/270x270"></div>
</div>
<div class="col-md-3 feature">
<div class="img-wrapper height2"><img class="img-responsive" src="https://placehold.it/270x540"></div>
</div>
<div class="col-md-3 feature">
<div class="img-wrapper"><img class="img-responsive" src="https://placehold.it/270x270"></div>
</div>
<div class="col-md-6 feature feature--width2">
<div class="img-wrapper"><img class="img-responsive" src="https://placehold.it/540x270"></div>
</div>
<div class="col-md-9 feature feature--width3 feature--width3">
<div class="img-wrapper last"><img class="img-responsive" src="https://placehold.it/810x270"></div>
</div>
</div>
</div>
When items are padded the height of images do not compensate for the padding, making the grid misaligned.
I have managed to fix this with setting a fixed height but that breaks the responsiveness of the grid and aspect ratios. Can someone point me to some well established techniques to solve this problem. As a final point I have tried various masonry solutions to no avail. My problem is quite similar to this - https://github.com/metafizzy/isotope/issues/877
I came across this answer - How to use border with Bootstrap
outline: #fff solid 10px;
It provides the same affect for borders around the image but isn't calculated by the browser when rendering containers.

Bootstrap row not aligning to right side of container

This is driving me nuts and it seems like the solution is a simple one I am overlooking. I have a row of three images and it is my understanding that bootstrap takes care of the alignment of content.
Shouldn't the third image be aligned to the right side of the container with all three being equally spaced?
http://codepen.io/amits/pen/oxbjmd?editors=1100
<div class="row">
<div class="col-md-4">
<img src="">
</div>
<div class="col-md-4">
<img src="">
</div>
<div class="col-md-4">
<img src="">
</div>
</div>
what am I missing?
you are missing the .container, and .img-responsive in img tag, plus you can have .col-sm-* for small devices and .col-xs-* for extra small devices.
added .col-xs-4 just for demo
take a look at the Docs
.container {
border: red solid
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-xs-4 col-md-4">
<img class="img-responsive" src="//lorempixel.com/1200/900">
</div>
<div class="col-xs-4 col-md-4">
<img class="img-responsive" src="//lorempixel.com/1200/900">
</div>
<div class="col-xs-4 col-md-4">
<img class="img-responsive" src="//lorempixel.com/1200/900">
</div>
</div>
</div>

Beginner struggling with a grid of images at tablet size in Bootstrap

OK, so first off I'm a designer that's been pushed into development. Have had to learn most of what I know within the last week. So apologies for my lack of knowledge.
I'm sure I've done things the wrong way but as you can see from the images I've tried creating a grid of images that will soon be clickable through to different parts of the site. Only issue is when the browser is scaled down to a tablet size things go wrong.
If anyone can help I'd appreciate it!
http://i.imgur.com/1cvq0d0.png
http://i.imgur.com/5nS6wdz.png
HTML
<div class="row">
<div class="col-md-6">
<div class="row-fluid">
<div class="col-sm-4 col-xs-4 box"><img src="images/b1.jpg" alt="test" class="img-responsive" />
<div class="carousel-caption-rob">
<h5>Malmaison Hotel</h5>
</div>
</div>
<div class="col-sm-4 col-xs-4 box"><img src="images/b2.jpg" alt="test" class="img-responsive" />
<div class="carousel-caption-rob">
<h5>Malmaison Hotel</h5>
</div>
</div>
<div class="col-sm-4 col-xs-4 box"><img src="images/b3.jpg" alt="test" class="img-responsive" />
<div class="carousel-caption-rob">
<h5>Malmaison Hotel</h5>
</div>
</div>
</div>
<div class="row-fluid">
<div class="col-sm-4 col-xs-4 box"><img src="images/b4.jpg" alt="test" class="img-responsive" />
<div class="carousel-caption-rob">
<h5>Malmaison Hotel</h5>
</div>
</div>
<div class="col-sm-4 col-xs-4 box"><img src="images/b5.jpg" alt="test" class="img-responsive" />
<div class="carousel-caption-rob">
<h5>Malmaison Hotel</h5>
</div>
</div>
<div class="col-sm-4 col-xs-4 box"><img src="images/b6.jpg" alt="test" class="img-responsive" />
<div class="carousel-caption-rob">
<h5>Malmaison Hotel</h5>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
This is all the box class you can see is
.box{
padding: 0px;
}
Keep up trying to learn this stuff! So I did not really understand why you have the content wrapped in a "col-md-6". Other then that, the "col-sm-4" in addition to the "col-xs-4" in somewhat redundant. Bootstrap is designed to be mobile first, so calling just "col-xs-4" is like calling "col-lg-4 col-md-4 col-sm-4 col-xs-4". Another note is "row-fluid" does not exist in Bootstrap 3.
If I were to build what you are trying to make today it would look like this:
https://gist.github.com/WilliHyde/dea9bd0e193f542a648e
Please note I just did the basic framework and did not do any of the styles for font color and such.
Good luck and keep it up! Remember, the Bootstrap docs are the key!

Weird bootstrap grid fail?

I'm not sure if I'm doing anything wrong but I'm getting a weird bug in a bootstrap grid when I resize my browser. It happens in a matter of a pixel and stops when I keep resizing. One of the images in the grid gets out of place and goes to the bottom. I'll attach a picture of the fail and another one of the normal.
Does anyone know what this bug is and how to fix it?
this is my code:
<section class="container-fluid">
<div class="row">
<div class="col-xs-12"> <img id="imgClickAndChange" src="img.jpg" onclick="changeImage(1)"/> </div>
</div>
<div class="row no-pad">
<div class="col-xs-12 col-md-6 col-lg-4">
<img class="grid" src="img1.jpg"/>
</div>
<div class="col-xs-12 col-md-6 col-lg-4">
<img class="grid" src="img2.jpg"/>
</div>
<div class="col-xs-12 col-md-6 col-lg-4">
<img class="grid" src="img1.jpg"/>
</div>
</div>
<div class="row no-pad">
<div class="col-xs-12 col-md-6 col-lg-4">
<img class="grid" src="img2.jpg"/>
</div>
<div class="col-xs-12 col-md-6 col-lg-4">
<img class="grid" src="img1.jpg"/>
</div>
<div class="col-xs-12 col-md-6 col-lg-4">
<img class="grid" src="img.jpg2"/>
</div>
</div>
</section>
Only css I used:
Btw it's a customized bootstrap (but the only thing I customized was the min width for a large screen from 1200px to 1900px and removed the grid glutter)
.grid { width: 100%;}
Thank you.
With Bootstrap, try applying the class img-responsive to your images to ensure they never exceed 100% width of their parent.
<img class="img-responsive" src="img1.jpg"/>
Documentation: http://getbootstrap.com/css/#images
If all the images are the same size, there is no issue:
https://jsbin.com/muzug/1/
https://jsbin.com/muzug/1/edit?html,css,output
Also, not necessary to have the col-xs-12, it will always be 100% under the last min-width class used.
Added a rounding error correction.
CSS:
.row.no-pad img {width:100.1%;}
.row.no-pad [class*="col-"] {padding:0;margin-bottom:-1px}
HTML
<section class="container-fluid">
<div class="row no-pad">
<div class="col-md-6 col-lg-4">
<img src="https://scontent-a-lhr.xx.fbcdn.net/hphotos-xap1/t31.0-8/1617132_1517052665201751_3430332756563801835_o.jpg">
</div>
<div class="col-md-6 col-lg-4">
<img src="https://scontent-a-lhr.xx.fbcdn.net/hphotos-xap1/t31.0-8/1617132_1517052665201751_3430332756563801835_o.jpg">
</div>
<div class="col-md-6 col-lg-4">
<img src="https://scontent-a-lhr.xx.fbcdn.net/hphotos-xap1/t31.0-8/1617132_1517052665201751_3430332756563801835_o.jpg">
</div>
<div class="col-md-6 col-lg-4">
<img src="https://scontent-a-lhr.xx.fbcdn.net/hphotos-xap1/t31.0-8/1617132_1517052665201751_3430332756563801835_o.jpg">
</div>
<div class="col-md-6 col-lg-4">
<img src="https://scontent-a-lhr.xx.fbcdn.net/hphotos-xap1/t31.0-8/1617132_1517052665201751_3430332756563801835_o.jpg">
</div>
<div class="col-md-6 col-lg-4">
<img src="https://scontent-a-lhr.xx.fbcdn.net/hphotos-xap1/t31.0-8/1617132_1517052665201751_3430332756563801835_o.jpg">
</div>
</div>
</div>