I am trying to use bootstrap in my HTML page to display a list of images. However, I am encountering issues where some images appear larger than others and the last image sometimes goes beyond the boundaries of my main container div. Additionally, when I resize the browser window, some items start overlapping. How can I address these problems?
Here is my CSS:
* { font-family: arial, sans-serif !important; }
body { padding-top: 50px; }
img.img-thumb {
height: 180px;
width: auto;
}
And here is my HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="main.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<title>Test Web</title>
</head>
<body>
<div class="container-fluid">
<div class="col-md-2">Left SideBar</div>
<div class="col-md-8">
<h2 class="text-center">Mens Shoes</h2>
<hr>
<div class="row">
<div class="col-sm-6 col-md-4 col-lg-3">
<h4>Shoe 1</h4>
<img src="image-url-here"
alt="shoe-1" class="img-thumb" />
<p class="list-price text-danger">List Price: £50 </p>
<button type="button" class="btn btn-sm btn-success" onclick="">Details</button>
</div>
<!-- Additional image and button code for other shoes -->
</div>
</div>
<div class="col-md-2">Right SideBar</div>
</div>
<br><br>
<hr>
<div class="col-md-12 text-center">
© Copyright 2013-2015
</div>
</body>
</html>
You can view the JSFiddle link here.
One solution I discovered is to replace 'width: auto' with 'max-width: 100%' in the CSS for img.img-thumb. However, this causes the images to lose their aspect ratio. If I use only 'max-width:100% and max-height:100%', the images become distorted in size.
How can I properly address this issue to ensure the images maintain their proportions while fitting within the designated container?