Haven't asked something here in a long time. I'm trying to build my design portfolio, and since I'm not really a front-end developer I lack a lot of knowledge, but that's why I'm here :)
I've got a container which is a DIV with a given padding. Inside I'll have a grid consisting of fluid-width cards. What would be the best option, or how to proceed towards that, for retaining the card aspect ratio (square) and the gutter between cards when resizing the parent element?
Simply put, I'm looking for something like the attached image:
So no matter the screen size, the gutter and padding will stay the same while the cards change their width to fill up the space.
I'm looking for something as CSS-pure as possible. Where should I look?
Thank you!
I am not sure if i got it right. Nenad's solution seems to be good. But i understood that the cards always stay 3 in a row doesn't matter how big or small the screen is (if this makes sense on every screen is another question now). I made you a fiddle in which you don't have to use pictures, you just have to include a little bit of JQuery Code, it's not much.
var divWidth = $('.square').width();
$('.square').height(divWidth);
Please see my fiddle here: https://jsfiddle.net/ee128fy2/
It would be no problem editing this for smaller screens to not have 3 squares in a row.
Note that the square height will not change when you resize your browser window, it will change on pageload. But anyway, i think no one will resize the window when looking on it on mobile phone or something.
Edit:
If you use pictures instead of jquery, resize will work live when scaling the browser window.
You can do this using boostrap https://jsfiddle.net/2Lzo9vfc/60/
HTML
<div class="container-fluid">
<div class="row">
<div class="col-sm-4 portfolio-item">
<img src="http://placehold.it/350x350" class="img-responsive" alt="">
</div>
<div class="col-sm-4 portfolio-item">
<img src="http://placehold.it/350x350" class="img-responsive" alt="">
</div>
<div class="col-sm-4 portfolio-item">
<img src="http://placehold.it/350x350" class="img-responsive" alt="">
</div>
</div>
<div class="row">
<div class="col-sm-4 portfolio-item">
<img src="http://placehold.it/350x350" class="img-responsive" alt="">
</div>
<div class="col-sm-4 portfolio-item">
<img src="http://placehold.it/350x350" class="img-responsive" alt="">
</div>
<div class="col-sm-4 portfolio-item">
<img src="http://placehold.it/350x350" class="img-responsive" alt="">
</div>
</div>
</div>
CSS
.portfolio-item {
margin: 20px 0;
}
#media(max-width: 768px) {
.portfolio-item {
margin: 20px auto;
width: 100%;
text-align: center;
}
.portfolio-item img{
margin: 0 auto;
}
}
Related
I have two images with two different size. I am using bootstrap in my project. But I cant place the images together which looks like both have same dimension. I have gone through similar questions and tried a lot. Please help me to sort this out.
<div class="row">
<div class="col-md-4">
<div class="thumbnail">
<a href="http://placehold.it/2048x1536" target="_blank">
<img src="http://placehold.it/2048x1536" alt="Nature">
</a>
</div>
</div>
<div class="col-md-4">
<div class="thumbnail">
<a href="http://placehold.it/1280x720" target="_blank">
<img src="http://placehold.it/1280x720" alt="Nature">
</a>
</div>
</div>
my css is
.thumbnail img {
height:250px;
width:100%;
}
You can do it by putting the picture as background-image for the 'div' tag and setting value of 'background-position' as 'stretch'.
Said that, if the images are of different resolution and you fit them into the same-size container it might look pixelated at times.
I am using the bootstrap framework, I am looking to have 3 images as shown in the jsfiddle link below act in a responsive manor when the window size changes/monitor size is too small to display the full sized images. It is important the images remain on the same line (if possible) with no spacing in between.
<img src="http://via.placeholder.com/660x160.png"><img src="http://via.placeholder.com/350x160.png"><img src="http://via.placeholder.com/350x160.png">
Thanks
https://jsfiddle.net/mztyoy7q/
Add a class to the image tags, and don't forget to add the bootstrap!
Just make sure you link the bootstrap, and you can use this free CDN:
https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css
and add the class
class="img-responsive"
to your img tags.
JSFiddle
EDIT: If you want the images on the same line, just create a couple divs.
first, create a parent div,
<div style="display:inline-block; width:100%; height:auto; background-color:#ff0000;">
<img class="img-responsive" src="http://via.placeholder.com/660x160.png">
<img class="img-responsive" src="http://via.placeholder.com/350x160.png">
<img class="img-responsive" src="http://via.placeholder.com/350x160.png">
</div>
This div element will be red with 100% width, and automatically resizing height.
Then add divs between every image with the style float:left; like so:
<div style="display:inline-block; width:100%; height:auto;background-color:#ff0000;">
<div style="float:left;">
<img class="img-responsive" src="http://via.placeholder.com/660x160.png">
</div>
<div style="float:left;">
<img class="img-responsive" src="http://via.placeholder.com/350x160.png">
</div>
<div style="float:left;">
<img class="img-responsive" src="http://via.placeholder.com/350x160.png">
</div>
</div>
Here is the updated JSFiddle If this works, please let me know!
Wrap your images to some grid/columns (e.g. .col-*) and make these images to fill 100% of available space (.img-responsive). This is a clean and elegant way to do it, using just bootstrap:
<div class="row">
<div class="col-xs-4">
<img class="img-responsive" src="http://via.placeholder.com/660x160.png">
</div>
<div class="col-xs-4">
<img class="img-responsive" src="http://via.placeholder.com/350x160.png">
</div>
<div class="col-xs-4">
<img class="img-responsive" src="http://via.placeholder.com/350x160.png">
</div>
</div>
https://jsfiddle.net/tvv89L1j/1/
About removing spaces, the easiest way would be just add your own styles to overwrite padding that bootstrap adds. You need to set padding-left and padding-right to 0 for columns (you can see where that padding comes from in browser inspector, of course).
I have written a code where 4 images are kept inside div side by side in cols.
Below is the code :
<div class="container-fluid">
<div class="row">
<div class="col-xs-3 col-sm-3 col-md-3">
<img src="image2.jpg" alt="1" style="width:100%; height:70%;" class="img-responsive" />
</div>
<div class="col-xs-3 col-sm-3 col-md-3">
<img src="image3.jpg" alt="1" style="width:100%; height:70%;" class="img-responsive"/>
</div>
<div class="col-xs-3 col-sm-3 col-md-3">
<img src="image4.jpg" alt="1" style="width:100%; height:70%;" class="img-responsive"/>
</div>
<div class="col-xs-3 col-sm-3 col-md-3">
<img src="image5.jpg" alt="1" style="width:100%; height:70%;" class="img-responsive"/>
</div>
</div>
</div>
This looks like this in full size window :
enter image description here
Now when the window size is minimized, the images looks like this :
enter image description here
I want the image to look the way it looks in the full size even after minimizing without the image getting stretched.
I was able to get the view of above images without it getting stretched when i removed the style: width:100%; height:70%; but then in full sized window the images had blank spaces between each other.
Please help me to get this sorted.
Using
class="img-responsive"
will make your images responsive across devices. In specific, and as per Bootstrap's documentation, it will add
max-width: 100%;
height: auto;
display: block;
to your image elements.
You will need to lose your inline styles
style="width:100%; height:70%;"
as they override everything else (Protip: never use them).
Lastly, if you don't want the blank spaces between images you'll need to force remove the padding for each column. Example:
div.col-xs-3 {
padding: 0;
}
Here is a sample codepen.
#FredRocha hey Fred, I tried using only img-reponsive & losing the inline styles but then the images were looking like this in full screen window size:
Example image
Maybe adding img-responsive class to image will fix the problem.
If someone could take a quick look at this code and give advice, that would be much appreciated.
I have some images that resize correctly on both iPad and PC screens. However, as soon as you try it on a phone/reduce browser window size, the image does not resize correctly.
CSS:
.col-md-2 {
width: 16.66666667%;
}
HTML:
<div class="col-md-2 col-sm-4">
<div class="timeline-thumb">
<div class="thumb">
<img src="images/timeline6.jpg" alt="">
</div>
<div class="overlay">
<div class="timeline-caption">
<h4>Wrapping Services</h4>
<p>Click for more info</p>
</div>
</div>
</div>
</div>
The image is 170px wide, and there are 6 of them in a line, that all highlight in grey (via CSS) when you roll the mouse over them.
When i resize my browser to that of a phone, they get bigger than before!
Any advice much appreciated.
If someone is knowledgeable on the subject and can help please contact me and ill try to provide any info you need.
Thanks.
I'm trying to understand if you are using Bootstrap. If so, you should add a class for the small devices, try to add a col-xs-4 or col-xs-6 to the DIV element that is "col-md-2 col-sm-4" now.
Looks like Bootstrap. If so, add the img-responsive helper class to your image.
<img class="img-responsive" src="images/timeline6.jpg" alt="">
This will allow your image to scale proportionately and fill 100% width of the containing div regardless of viewport size.
I have a set of Bootstrap thumbnails on my web page and I have set all the images with class .img-responsive. When I open the page on a mobile browser the thumbnails are appearing too small and I can't even resize them with css.
Here are my thumbnails:
<div class="row">
<div class="col-xs-6 col-md-3">
<a href="#" class="thumbnail">
<img src="images/thumbnails/traditional.jpg" class="img-rounded img-responsive" alt="...">
</a>
</div>
<div class="col-xs-6 col-md-3">
<a href="#" class="thumbnail">
<img src="images/thumbnails/mehndi.jpg" class="img-rounded img-responsive" alt="...">
</a>
</div>
... altogether 12 thumbnails
</div>
I have tried to edit the size of the thumbnails for mobile phone size devices with the following media query:
#media(max-width:767px){
.thumbnail > img {
height:70px;
width:120px;
}
}
However the width doesn't seem to surpass 80px, it seems like I can only set width up to around 80px and anything higher won't do anything.
If I leave the thumbnails like they are without trying the above CSS code they appear too small on mobile devices and I need a way to increase the size of the thumbnails on mobile devices only.
Here is a link to the site:
Change col-xs-6 to col-xs-12
So instead of
<div class="col-xs-6 col-md-3">
You'll have
<div class="col-xs-12 col-md-3">
This will make it so that each thumbnail will take up the full width of the phone, instead of having two across.
I have fixed the problem, I found that I had the below code elsewhere in my CSS that I didn't take notice of. This below media query was what made my images appear so small on mobile devices, I took it out and now images appear fine. Thanks for the help guys.
#media(max-width:767px){
.thumbnail > img {
height:40px;
}
}