I have a div that lists screenshots for my software that I'm displaying on a website. When the screen is big the images align properly.
The problem is when I view it on the phone or change the window size on the computer to collapse the items, there's empty space where it's not being aligned properly for some reason. See Picture below.
Here is the Code on the index page. In my opinion, everything should work fine without adjustments.
Things I've tried:
-Removing the container and row classes.
-Changing the width of the images all the way down to 80%, which even 100% SHOULD work
-Adding class="img-responsive" as seen in another thread.
-Removing margins and padding for the divs the images are in.
<!-- Screenshots -->
<div id="screenshots">
<div class="container">
<br>
<div class="row text-center"> <!-- Screenshot DIV -->
<h2>Screenshots<h2>
<div class="col-md-2 col-xs-6">
<img src="images/screenshots/dashboard.png" alt="Dashboard SS" class="img-responsive" width="100%" />
</div>
<div class="col-md-2 col-xs-6">
<img src="images/screenshots/lotmanager.png" alt="Lot Manager SS" class="img-responsive" width="100%" />
</div>
<div class="col-md-2 col-xs-6">
<img src="images/screenshots/register.png" alt="Register SS" class="img-responsive" width="100%" />
</div>
<div class="col-md-2 col-xs-6">
<img src="images/screenshots/sell.png" alt="Auction SS" class="img-responsive" width="100%" />
</div>
<div class="col-md-2 col-xs-6">
<img src="images/screenshots/checkout.png" alt="Checkout SS" class="img-responsive" width="100%"/>
</div>
<div class="col-md-2 col-xs-6">
<img src="images/screenshots/samplereceipt.png" alt="Receipt SS" class="img-responsive" width="100%" />
</div>
</div><!-- /.Screenshot DIV -->
<br>
</div><!-- /.container -->
</div><!-- /.screenshots -->
Any help would be appreciated.
One Error in Your Code, Please check after correct /h2
<h2>Screenshots</h2>
It is due to different height of the images. What can u do Set the parent div of the img to the maximum height from the group of the images?
var maxheight;
$('#screenshots .container > div > img').each(function(){
var currHeight = $(this).height();
if(maxHeight < currHeight) {
maxHeight = currHeight;
}
});
if(window.width() < 768) {
$('#screenshots .container > div').hieght(maxHeight);
}
Related
I'm trying to get three images to cumulatively take up an entire bootstrap row (effectively each taking up a column that spans 4). However, my code right now has them leaving gaps in between, and on either side. I've attached a screenshot of the problem, with the ideal solution to have the images take up the entire space without leaving any gaps. Below is the relevant html:
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-4">
<image class="img-responsive" src="http://res.cloudinary.com/duocsoiqy/image/upload/v1500928572/Waterloo_Image_abjgbc.png" style="max-height:100%;width:100%">
</div>
<div class="col-md-4">
<image class="img-responsive" src="http://res.cloudinary.com/duocsoiqy/image/upload/v1500928930/New_York_Image_ke8tya.png" style="max-height:100%;width:100%">
</div>
<div class="col-md-4">
<image class="img-responsive" src="http://res.cloudinary.com/duocsoiqy/image/upload/v1500929276/Columbus_Image_t7oren.png" style="max-height:100%;width:100%">
</div>
</div>
</div>
</body>
Screenshot of Issue
Bootstrap columns have default right and left padding of 15px. Inspect the columns in devtools and you will see it. You need to over ride it with your own custom css.
Here you go with a solution https://jsfiddle.net/hhzbxrbf/
.col-md-4 {
padding: 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-4">
<image class="img-responsive" src="http://res.cloudinary.com/duocsoiqy/image/upload/v1500928572/Waterloo_Image_abjgbc.png" style="max-height:100%;width:100%" />
</div>
<div class="col-md-4">
<image class="img-responsive" src="http://res.cloudinary.com/duocsoiqy/image/upload/v1500928930/New_York_Image_ke8tya.png" style="max-height:100%;width:100%" />
</div>
<div class="col-md-4">
<image class="img-responsive" src="http://res.cloudinary.com/duocsoiqy/image/upload/v1500929276/Columbus_Image_t7oren.png" style="max-height:100%;width:100%" />
</div>
</div>
</div>
</body>
When shrinking the screen, these images are overlapping each other. I have made no changes to the css for container-fluid or row.
<div class="container-fluid bg-grey">
<div class="row center">
<div class="col-sm-4">
<img src="http://www.fpcbp.com/wp-content/gallery/tkGallery/OYIaJ1KK.png" width="425" height="319" />
</div>
<div class="col-sm-4">
<img src="http://www.fpcbp.com/wp-content/gallery/tkGallery/OYIaJ1KK.png" width="425" height="319" />
</div>
<div class="col-sm-4">
<img src="http://www.fpcbp.com/wp-content/gallery/tkGallery/OYIaJ1KK.png" width="425" height="319" />
</div>
</div>
</div>
I would like the images to just stack on top of each other, instead of overlapping.
Thanks
The columns will overlap because the <img> elements have a fixed width value. col-*-* have a set percentage width and as soon as that becomes smaller than the width set on the images, overlapping will occur.
To make images responsive you can remove the width property and use the class .img-responsive so that the <img> doesn't exceed the width of the column. It utilizes max-width: 100%.
<img class="img-responsive" src="..." />
You should defined your columns for narrower screen, e.g. col-xs-12. It means that on screens smaller than 768px each column take all the available space, so they stack.
In your code you have 3 columns in a single row and a single column take 33.33% of available space. What's more, you have declared fixed sized of your images. In order to make them responsive, you could use Bootstrap img-responsive class. Notice though, that you must remove earlier fixed height and width. Otherwise images won't scale.
If any of the two valid answers above and below did not work for you, try to add the css attributes attaching your own class to the images:
.myclass{max-width: 100%; height: auto;}
<div class="container-fluid bg-grey">
<div class="row center">
<div class="col-sm-4 col-md-4 col-xs-12">
<img class="img-responsive" src="http://www.fpcbp.com/wp-content/gallery/tkGallery/OYIaJ1KK.png" width="425" height="319" />
</div>
<div class="col-sm-4 col-md-4 col-xs-12">
<img class="img-responsive" src="http://www.fpcbp.com/wp-content/gallery/tkGallery/OYIaJ1KK.png" width="425" height="319" />
</div>
<div class="col-sm-4 col-md-4 col-xs-12">
<img class="img-responsive" src="http://www.fpcbp.com/wp-content/gallery/tkGallery/OYIaJ1KK.png" width="425" height="319" />
</div>
</div>
</div>
I´m using the bootstrap grid system with full-width and I want to have a section, where I have four img-elements with equal margin and the margin should be responsive. The section is in the center of the page.
I could say for every img-element margin-right: 20px or something like this, but can I get this also responsive?
<div class="row" id="content_services">
<div class="col-md-offset-2 col-md-8">
<section id="services_section">
<img src="pictures/test.jpg" alt="Test" class="img-responsive">
<img src="pictures/test.jpg" alt="Test" class="img-responsive">
<img src="pictures/test.jpg" alt="Test" class="img-responsive">
<img src="pictures/test.jpg" alt="Test" class="img-responsive">
</section>
</div>
</div><!-- END ROW CONTENT_SERVICES -->
The stylesheet:
#services_section{
}
#services_section img{
height: 275px;
width: 275px;
display: inline;
}
if its only ever going to be 4 elements - use a nested column structure. Each image will display across the page in a single row across the screen on medium and large viewports, will display in pairs on small viewports and will stack vertically on small viewports. You will still need to style the images to display in the center of each (either with a text-center class on the parent div as I have done or via css on each img). If you need to alter the number of images - remember that the magic number is 12 - each column can be divided into 12 columns so you can alter the sizings for different numbers of image elements.
Also just note that a section semantically requires a heading (h1 - h6 - which defines its title ) within its structure to be valid html5. Hope this helps, Gavgrif
<div class="row" id="content_services">
<div class="col-md-offset-2 col-md-8 text-center">
<section id="services_section">
<div class="col-md-3 col-sm-6">
<img src="pictures/test.jpg" alt="Test" class="img-responsive">
</div>
<div class="col-md-3 col-sm-6">
<img src="pictures/test.jpg" alt="Test" class="img-responsive">
</div>
<div class="col-md-3 col-sm-6">
<img src="pictures/test.jpg" alt="Test" class="img-responsive">
</div>
<div class="col-md-3 col-sm-6">
<img src="pictures/test.jpg" alt="Test" class="img-responsive">
</div>
</section>
</div>
</div><!-- END ROW CONTENT_SERVICES -->
I'm trying to align each image to the left and right of the text in the "wrapper2 panel-footer center-block" div. It correctly aligns the left image, but the right image is actually going "under" the div for some reason.
.wrapper2 {
max-width: 800px;
float: none;
margin: 0 auto;
}
<div class="wrapper2 panel-footer center-block">
<div class="pull-left">
<img alt="logo" src="https://cdn4.iconfinder.com/data/icons/miu-flat-social/60/stackoverflow-128.png" />
</div>
<p><small>Copyright © All Rights Reserved.</small>
</p>
<div class="pull-right">
<img alt="logo" src="https://cdn4.iconfinder.com/data/icons/miu-flat-social/60/stackoverflow-128.png" />
</div>
Any reason for this?
To align divs next to each other in Bootstrap you utilize columns. There are 12 columns in a row, so in the example below I put each element in a 4 wide using the col-xs-4 class.
I also added the img-responsive class to both of the images so they scale down correctly on smaller devices.
<div class="wrapper2 panel-footer">
<div class="col-xs-4">
<div class="pull-left"><img class="img-responsive" alt="logo" src="https://cdn4.iconfinder.com/data/icons/miu-flat-social/60/stackoverflow-128.png" /></div>
</div>
<div class="col-xs-4">
<p><small>Copyright © All Rights Reserved.</small></p>
</div>
<div class="col-xs-4">
<div class="pull-right"><img class="img-responsive" alt="logo" src="https://cdn4.iconfinder.com/data/icons/miu-flat-social/60/stackoverflow-128.png" /></div>
</div>
</div>
Here's a working fiddle link: https://jsfiddle.net/88ebLj7e/
You can find more information on the Bootstrap grid here: https://getbootstrap.com/examples/grid/
<p> Tag is outside the pull-left class. That's what made it looks "under" the div. When you use pull-left. all should be INSIDE the class.
From your codes, <p><small> belongs to wrapper2 not pull-left or pull-right.
If you need more flexible usage, you can use what James Ives suggest. Otherwise, you should change it into like this:
Add one line in your stylesheet as follows:
<style>
.wrapper2 p{float:left; padding-left:30%;}
</style>
<div class="wrapper2 panel-footer center-block">
<div class="pull-left"><img alt="logo" src="https://cdn4.iconfinder.com/data/icons/miu-flat-social/60/stackoverflow-128.png" /></div>
<p><small>Copyright © All Rights Reserved.</small></p>
<div class="pull-right"><img alt="logo" src="https://cdn4.iconfinder.com/data/icons/miu-flat-social/60/stackoverflow-128.png" /></div>
</div>
So, what you need now is to decide padding-left value.
Hopes, it helps.
I want to stack four images which are next to each other at desktop size, to be above each other in 2 columns (1 and 2 3 and 4) in mobile screen size, using the bootstrap 12 column grid. The original 4 imgs are similar but are not exactly the same in size. The heights vary between 40 and 57 px and the widths are between 176 and 220 px. When displayed non-responsive they come out the way they should in desktop size, next to each other. However, when I make them responsive by adding width=100% in the html, the last one comes out magnified compared to the rest, both in desktop and in mobile size, and the first one takes up more space than the rest if I inspect them. The pics do line up in 2 columns in mobile size, but the last pic is not in line with the third one but displaced a paragraph below. If I adjust the size of the last pic to 85% then the sizes are okay, but issue with the pic being out of position still remains.
Here is the code:
<section id="section">
<div class = "container">
<div class = "row">
<div class="col-md-3 col-sm-3 col-xs-6 col text-center">
<img src = "img/1.png" style='width:100%;' alt="Null" />
</div>
<div class="col-md-3 col-sm-3 col-xs-6 text-center">
<img src = "img/2.png" style='width:100%;' alt="Null" />
</div>
<div class="col-md-3 col-sm-3 col-xs-6 text-center">
<img src = "img/3.png" style='width:100%;' alt="Null" />
</div>
<div class="col-md-3 col-sm-3 col-xs-6 text-center">
<img src = "img/4.png" style='width:100%;' alt="Null" />
</div>
</div>
</div>
</section>
It depends by use of float on items of different height.
You have 2 options, one adding a special div provided by Bootstrap, that is visible only in mobile breakpoints:
<div class="col-md-3 col-sm-3 col-xs-6 text-center">
<img src = "img/2.png" style='width:100%;' alt="Null" />
</div>
<div class="clearfix visible-xs"></div>
<div class="col-md-3 col-sm-3 col-xs-6 text-center">
<img src = "img/3.png" style='width:100%;' alt="Null" />
</div>
<div class="col-md-3 col-sm-3 col-xs-6 text-center">
<img src = "img/4.png" style='width:100%;' alt="Null" />
</div>
</div>
</div>
You have to add it after each two elements.
Another solution is to set auto-clear with only css (you have to manually set the right media query value) and the idea is to clear:left every 3rd element:
#media screen and (max-width: 720px) {
.col-xs-6:nth-of-type(2n+1) {
clear:left;
}
}