I am using Bootstrap 4 and I have a template layout with
<div class="navbar">
...
</div>
<div class="container">
{{content}}
</div>
This works in almost all cases. However, sometimes I want an image in the content to take up the full width, but this is not possible due to the .container
which uses left-padding
and right-padding
.
I could solve this by adding the .container
class in each view at the right places instead of in my template layout file, but this will become quite annoying. Especially if I have a CMS where different authors can write articles, and if they want a full-width image in the middle of their article, they have to write raw html to be something like
<div class="container">
some text
</div>
<div class="full-width-image">
<img src="" alt="">
</div>
<div class="container">
more text
</div>
..
How could I solve this problem?
“bootstrap full width image” Code Answer's you have to set the width of image to 100%, for that you can use Bootstrap class "w-100". keep in mind that "container-fluid" and "col-12" class sets left and right padding to 15px and "row" class sets left and right margin to "-15px" by default.
Containers. Containers are the most basic layout element in Bootstrap and are required when using our default grid system. Choose from a responsive, fixed-width container (meaning its max-width changes at each breakpoint) or fluid-width (meaning it's 100% wide all the time).
container-fluid class provides a full width container, spanning the entire width of the viewport.
you can use vw
units with negative margin. And it's responsive friendly.
.full-width-image {
width: 100vw;
position: relative;
left: 50%;
margin-left: -50vw;
}
.full-width-image img {
width: 100%;
}
See my fiddle: https://jsfiddle.net/ondrejruzicka/07y0o746/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With