Maintain image aspect ratio in carousel
The issue lays here, on bootstrap CSS:
img {
max-width: 100%;
width: auto 9;
height: auto;
vertical-align: middle;
border: 0;
-ms-interpolation-mode: bicubic;
}
Having set max-width: 100%;
the image won't be any larger than the viewport. You need to override that behavior on your CSS:
.carousel img {
position: absolute;
top: 0;
left: 0;
min-width: 100%;
height: 500px;
max-width: none;
}
Note the max-width: none;
added at the bottom. This is the default max-width value and unsets the limit.
Here's your fiddle updated.
How to make Bootstrap Carousel maintain image aspect ratio?
Carousel images are responsive by default in latest Bootstrap 3 { display: block; max-width: 100%; height: auto; }
. So, there is no need to add an.img-responsive
class to your images. (Also, there is no need to wrap the .carousel-caption
in a .container
)
If you start with the sample markup here and remove your extra style overrides, you can see that the aspect ratio is properly maintained on different screen sizes. You can verify this using the same link above.
Related Topics
Negative Margin and Background
Play Audio Local File with HTML
How to Use Access-Control-Allow-Origin? Does It Just Go in Between The HTML Head Tags
An Url to a Windows Shared Folder
Why Does 'Transform' Break 'Position: Fixed'
Wrap a Text Within Only Two Lines Inside Div
Regex to Match All HTML Tags Except <P> and </P>
Uiwebview with Contenteditable (HTML Editing), First Responder Handling
How to Create a Teardrop in HTML
Center a Large Image of Unknown Size Inside a Smaller Div with Overflow Hidden
How to Center Multiple Divs Inside a Container in CSS
HTML - Two Tables Side by Side
How to Force Download with HTML/JavaScript
How to Center Content in a Bootstrap Column
Should I Use <Ul>S and <Li>S Inside My <Nav>S
Convert Svg Path Data to 0-1 Range to Use as Clippath with Objectboundingbox
Changing The Highlight Color When Selecting Text in an HTML Text Input