Hi I am new in using bootstrap and I am not very good handling responsive image in bootstrap.
So here is my question.
I have images result formation like this on 992px:
but when I change my screen width to smaller media (e.g:520px) the images come in line with no gaps in it.
It become like this.
I want it like this with padding(gaps) in it.
here is my HTML code:
<!--two columes 3/1-->
<div id="first" class="row">
<div class="col-md-8"><img src="http://placehold.it/640x450" class="img-responsive"></div>
<div class="col-md-4"><img src="http://placehold.it/300x450" class="img-responsive"></div>
</div>
<div id="clean">
<!--two columes 3/1-->
<div id="second" class="row">
<div class="col-md-8">
<img src="http://placehold.it/640x100" class="img-responsive">
<br>
<br>
<img src="http://placehold.it/640x330" class="img-responsive"></div>
<div class="col-md-4"><img src="http://placehold.it/300x470" class="img-responsive"></div>
</div>
<!--two columes half half-->
<div class="row" id="third">
<div class="col-md-6"><img src="http://placehold.it/470x470" class="img-responsive"></div>
<div class="col-md-6"><img src="http://placehold.it/470x470" class="img-responsive"></div>
</div>
<!--four columes-->
<div class="row" id="forth">
<div class="col-xs-6 col-sm-3"><img src="http://placehold.it/250x250" class="img-responsive"></div>
<div class="col-xs-6 col-sm-3"><img src="http://placehold.it/250x250" class="img-responsive"></div>
<!-- Add the extra clearfix for only the required viewport -->
<div class="clearfix visible-xs"></div>
<div class="col-xs-6 col-sm-3"><img src="http://placehold.it/250x250" class="img-responsive"></div>
<div class="col-xs-6 col-sm-3"><img src="http://placehold.it/250x250" class="img-responsive"></div>
</div>
And here is CSS:
#first
{
padding:20px;
}
#second
{
padding:20px;
}
#third
{
padding:20px;
}
#forth
{
padding:20px;
}
And this is its fiddle
You can use two sets of images.
<div id="first" class="row">
<div class="col-md-8">
<img src="http://placehold.it/640x450" class="img-responsive hidden-xs hidden-sm">
<img src="http://placehold.it/700x450" class="img-responsive visible-xs visible-sm">
</div>
<div class="col-md-4">
<img src="http://placehold.it/300x450" class="img-responsive hidden-xs hidden-sm">
<img src="http://placehold.it/700x450" class="img-responsive visible-xs visible-sm">
</div>
</div>
And the css can go like:
.img-responsive {
width: 100%;
}
It will be a good option to use 2 sets in this case because re-sizing a 640x450 image to 700x450 will alter its aspect ratio.
You can read more about responsive utilities provided by bootstrap here:
http://getbootstrap.com/css/#responsive-utilities
Bootstrap don't wan't to increase your images sizes- that's the deal.
Easy way to solve the problem:
use this meta-tag <meta name="viewport" content="width=device-width, initial-scale=1">
and media queries, like this:
#media all and (max-width: 699px) and (min-width: 520px), (min-width: 1151px) {
img {
width: 700px;
height: auto;
}
}
It's just example. Change exactly width of query for your need.
Related
Im wondering why do i have space between second text which is from first row and first text which is on second row? I find it annoying, why does it happen? Is there any way to fix it?
[IMG]http://i67.tinypic.com/2zhe0xg.jpg[/IMG]
This is how it looks on desktop:
[IMG]http://i65.tinypic.com/2eby5bs.png[/IMG]
HTML:
<div class="container-fluid">
<div class="row mt-5 mb-5 ml-3 mr-3">
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="row">
<div class="col-lg-8 col-md-8 col-sm-8">
<img class="img-fluid img-thumbnail" src="https://static-assets-prod.epicgames.com/fortnite/static/webpack/8704d4d5ffd1c315ac8e2c805a585764.jpg">
</div>
<div class="col-lg-4 col-md-4 col-sm-4text">
<div class="b">
<p>Somethin ggoes here maybe</p>
</div>
</div>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="row">
<div class="col-lg-8 col-md-8 col-sm-8">
<img class="img-fluid img-thumbnail" src="https://static-assets-prod.epicgames.com/fortnite/static/webpack/8704d4d5ffd1c315ac8e2c805a585764.jpg">
</div>
<div class="col-lg-4 col-md-4 col-sm-4 text">
<div class="b">
<p>Something goes here maybe</p>
</div>
</div>
</div>
</div>
</div>
<div class="row mt-5 mb-5 ml-3 mr-3">
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="row">
<div class="col-lg-8 col-md-8 col-sm-8">
<img class="img-fluid img-thumbnail" src="https://static-assets-prod.epicgames.com/fortnite/static/webpack/8704d4d5ffd1c315ac8e2c805a585764.jpg">
</div>
<div class="col-lg-4 col-md-4 col-sm-4 text">
<div class="b">
<p>Somethin ggoes here maybe</p>
</div>
</div>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="row">
<div class="col-lg-8 col-md-8 col-sm-8">
<img class="img-fluid img-thumbnail" src="https://static-assets-prod.epicgames.com/fortnite/static/webpack/8704d4d5ffd1c315ac8e2c805a585764.jpg">
</div>
<div class="col-lg-4 col-md-4 col-sm-4 text">
<div class="b">
<p>Something goes here maybe</p>
</div>
</div>
</div>
</div>
</div>
</div>
CSS:
.row > .text > .b {
display: -webkit-box;
height: 70%;
line-height: 1.3;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
}
I tried multiple solutions but couldnt get it to work
There are some styles you should definitely include in future questions so we can diagnose conflicts. For future reference, include any styles for classes you have assigned.
As far as what I can tell just from your code and screenshots, though, I'd say setting margin: 0; on your 2 divs in a media query for the affected breakpoint would work, but I'd also like to add a suggestion that will be a bit less messy for you using flexbox.
/* Make your container a flexbox */
.container {
display: flex;
}
/* Give flex grow value of 1 to keep all inner containers equal size */
.article {
flex: 1;
margin: 5px;
}
/* Sizing the image */
.article>img {
max-width: 400px;
}
.article>h1 {
font-size: 12px;
}
/* You could also just set the flex-direction to column, but displaying as block at the breakpoint will achieve the layout you're looking for on mobile. 500px is a trivial guess, use inspector to find the sweet spot */
#media (max-width:500px) {
.container {
display: block;
}
}
<div class="container">
<div class="article">
<img src="https://3bonlp1aiidtbao4s10xacvn-wpengine.netdna-ssl.com/wp-content/uploads/2018/05/epic-fortnite.jpg" />
<h1>
Something here maybe.
</h1>
</div>
<div class="article">
<img src="https://3bonlp1aiidtbao4s10xacvn-wpengine.netdna-ssl.com/wp-content/uploads/2018/05/epic-fortnite.jpg" />
<h1>
Something here maybe.
</h1>
</div>
</div>
<div class="container">
<div class="article">
<img src="https://3bonlp1aiidtbao4s10xacvn-wpengine.netdna-ssl.com/wp-content/uploads/2018/05/epic-fortnite.jpg" />
<h1>
Something here maybe.
</h1>
</div>
<div class="article">
<img src="https://3bonlp1aiidtbao4s10xacvn-wpengine.netdna-ssl.com/wp-content/uploads/2018/05/epic-fortnite.jpg" />
<h1>
Something here maybe.
</h1>
</div>
</div>
You can read up a bit more on flexbox in this CSS-Tricks article as well. If you're confused on anything here, feel free to comment and I'll try and answer the best I can. I've composed a fiddle here too so you can see how it responds when resizing.
So I have basically used manual percentages to make these images lie next together. As you see they are not very neatly layout or organized. How can I make it look more dashing?
Here's the code:
<div class="jumbotron jumbotron-fluid" style=" margin-top: 90px; ">
<div class="container">
<div class="row">
<div class="col-lg-2">
<img src="./assets/img/glass.jpg" class="img-responsive " style="width:95%"/>
<img src="./assets/img/rift.jpg" class="img-responsive m-y-1" style="width:95%;"/>
</div>
<div class="col-lg-8">
<img src="./assets/img/mhacks.jpg" class="img-responsive" style="width:100%; "/>
</div>
<div class="col-lg-2">
<img src="./assets/img/mindwave.png" class="img-responsive" style="width:120%;"/>
<img src="./assets/img/VR.png" class="img-responsive m-y-1" style="width:120%;"/>
</div>
</div>
</div>
</div>
Here's how it looks like:
http://imgur.com/e2I3yLu
Also here's the link to the website:
monajalal.github.io
Any suggestion is really appreciated. I wonder if there's a more straightforward method to image layout or any automatic method?
Set each image as a background image in a div:
<div class="jumbotron jumbotron-fluid" style=" margin-top: 90px; ">
<div class="container">
<div class="row">
<div class="col-lg-2">
<div style="background: url('./assets/img/glass.jpg'); background-size: cover;" class="img-responsive"></div>
<div style="background: url('./assets/img/rift.jpg'); background-size: cover;" class="img-responsive"></div>
</div>
<div class="col-lg-8">
<div style="background: url('./assets/img/mhacks.jpg'); background-size: cover;" class="img-responsive-large"></div>
</div>
<div class="col-lg-2">
<div style="background: url('./assets/img/mindwave.png'); background-size: cover;" class="img-responsive"></div>
<div style="background: url('./assets/img/VR.png'); background-size: cover;" class="img-responsive"></div>
</div>
</div>
</div>
</div>
Then set this css:
.img-responsive {padding-top: 60%; margin-bottom: 10px;}
.img-responsive-large {height: 208px; margin-bottom: 10px;}
#media screen and (max-width: 940px) {
.img-responsive-large {height: auto; padding-top: 60%;}
}
Try this... What I did was work with the grid. Use the padding from columns and even it with margins between the images, also set the images to 100% width. Class img-responsive sets a max-width of 100%, at least this way the image will fill the column.
<div class="jumbotron jumbotron-fluid">
<div class="container">
<div class="row">
<div class="col-lg-8">
<img src="http://www.online-image-editor.com//styles/2014/images/example_image.png" class="img-responsive"/>
</div>
<div class="col-lg-2">
<img src="http://www.online-image-editor.com//styles/2014/images/example_image.png" class="img-responsive "/>
<img src="http://www.online-image-editor.com//styles/2014/images/example_image.png" class="img-responsive m-y-1"/>
</div>
<div class="col-lg-2">
<img src="http://www.online-image-editor.com//styles/2014/images/example_image.png" class="img-responsive"/>
<img src="http://www.online-image-editor.com//styles/2014/images/example_image.png" class="img-responsive m-y-1"/>
</div>
</div>
</div>
</div>
Remove the inline styling - and instead target the images in the css and add this.
.jumbotron img { width: 100%; margin: 15px 0; }
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>
I have a grid of 4 x 2 with product images and some text overlaying the image. The problem is that the images are going to be all different aspect ratios.
What tends to happen is that if one image is significantly higher than the rest, it will push the other images out of alignment. I am trying to find a way to keep all the boxes the same height, with the text in the same position on each image, with just the picture scaling itself down to fit.
This is also responsive, so please enlarge the preview window on jsfiddle to see the issue I am having.
In this example, I have used the correct image dimensions.
JSFiddle: https://jsfiddle.net/w533z8Lg/3/
EDIT: Removing the max-height:292px and just having height:292px for the images works in terms of the layout is correct, but the smaller images are stretched to that height, and resizing doesn't keep the aspect ratio.
EDIT 2: I found this JSFiddle which was a solution to someone else with the same issue, I will try to understand it. http://jsfiddle.net/ETkkR/7/
HTML:
<div class="row featured_products list-group">
<div class="item col-xs-12 col-sm-6 col-md-4 col-lg-3 featured_product">
<div class="padding">
<div class="border">
<div class="innerpadding product-thumbnail"><img class="img-responsive" src="http://dummyimage.com/226x272/8f8f8f/575757.jpg" /><span class="featured_product_title"><span>Item 1</span></span>
</div>
</div>
</div>
</div>
<div class="item col-xs-12 col-sm-6 col-md-4 col-lg-3 featured_product">
<div class="padding">
<div class="border">
<div class="innerpadding product-thumbnail"><img class="img-responsive" src="http://dummyimage.com/226x270/8f8f8f/575757.jpg" /><span class="featured_product_title"><span>Item 2</span></span>
</div>
</div>
</div>
</div>
<div class="item col-xs-12 col-sm-6 col-md-4 col-lg-3 featured_product">
<div class="padding">
<div class="border">
<div class="innerpadding product-thumbnail"><img class="img-responsive" src="http://dummyimage.com/226x272/8f8f8f/575757.jpg" /><span class="featured_product_title"><span>Item 3</span></span>
</div>
</div>
</div>
</div>
<div class="item col-xs-12 col-sm-6 col-md-4 col-lg-3 featured_product">
<div class="padding">
<div class="border">
<div class="innerpadding product-thumbnail"><img class="img-responsive" src="http://dummyimage.com/226x235/8f8f8f/575757.jpg" /><span class="featured_product_title"><span>Item 4</span></span>
</div>
</div>
</div>
</div>
<div class="item col-xs-12 col-sm-6 col-md-4 col-lg-3 featured_product">
<div class="padding">
<div class="border">
<div class="innerpadding product-thumbnail"><img class="img-responsive" src="http://dummyimage.com/226x274/8f8f8f/575757.jpg" /><span class="featured_product_title"><span>Item 5</span></span>
</div>
</div>
</div>
</div>
<div class="item col-xs-12 col-sm-6 col-md-4 col-lg-3 featured_product">
<div class="padding">
<div class="border">
<div class="innerpadding product-thumbnail"><img class="img-responsive" src="http://dummyimage.com/226x160/8f8f8f/575757.jpg" /><span class="featured_product_title"><span>Item 6</span></span>
</div>
</div>
</div>
</div>
<div class="item col-xs-12 col-sm-6 col-md-4 col-lg-3 featured_product">
<div class="padding">
<div class="border">
<div class="innerpadding product-thumbnail"><img class="img-responsive" src="http://dummyimage.com/226x272/8f8f8f/575757.jpg" /><span class="featured_product_title"><span>Item 7</span></span>
</div>
</div>
</div>
</div>
<div class="item col-xs-12 col-sm-6 col-md-4 col-lg-3 featured_product">
<div class="padding">
<div class="border">
<div class="innerpadding product-thumbnail"><img class="img-responsive" src="http://dummyimage.com/226x292/8f8f8f/575757.jpg" /><span class="featured_product_title"><span>Item 8</span></span>
</div>
</div>
</div>
</div>
</div>
CSS:
.featured_product {
padding-left:10px;
padding-right:10px;
margin-bottom:15px;
}
.featured_products div.padding {
padding:5px 10px;
}
.featured_products div.padding div.border {
border:1px solid #EAEAEA;
}
.featured_products div.padding div.border div.innerpadding {
padding:5px;
text-align:center;
width:100%;
}
.featured_products div.padding div.border div.innerpadding img {
max-height:292px;
display:inline-block;
}
span.featured_product_title {
position: absolute;
bottom:6px;
left: 0;
width: 100%;
background-color:RGBa(255, 255, 255, 0.6);
vertical-align:center;
line-height:50px;
height:50px;
color:#46436f;
font-weight:bold;
font-size:1.3em;
}
You can't make all the images as the same size without cutting off.
What you can do is adding the necessary clear fix on the items, for every size you're targeting. That will make the them stay in the correct grid. Bootstrap targets those three breakpoints.
Demo: http://jsfiddle.net/w533z8Lg/5/
#media (min-width: 768px) {
.featured_products .item:nth-child(2n+1) {
clear: both;
}
}
#media (min-width: 992px) {
.featured_products .item:nth-child(2n+1) {
clear: none;
}
.featured_products .item:nth-child(3n+1) {
clear: both;
}
}
#media (min-width: 1200px) {
.featured_products .item:nth-child(3n+1) {
clear: none;
}
.featured_products .item:nth-child(4n+1) {
clear: both;
}
}
I have had this issue before with projects I was working on. What I ended up doing was using the Masonry library in conjunction with Bootstrap. http://masonry.desandro.com/. My conditions were the aspect ratio had to remain, they had to have the same width, and the I knew the heights would be unpredictable.
Granted, it doesn't keep all things in a straight horizontal line, but it sure eliminates the huge empty white spaces that you're talking about.
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>