I have image that have space when i look at device with resolution sm and xs how to make it fit with the grid?
here is my code
<div class="container">
<div class="row">
<div class="col-md-7">
<img src="http://placehold.it/550x350" class="img-responsive">
</div>
<div class="col-md-5">
<h2>How do you auto-resize a large image so that it will fit into a smaller width div container whilst maintaining it's width:height ratio?</h2>
<p>How do you auto-resize a large image so that it will fit into a smaller width div container whilst maintaining it's width:height ratio?</p>
</div>
</div>
</div>
from the resolution 991px to 581px I get blank space from image (like it didn't fit to the grid)
http://www.bootply.com/10CUN9fXqG#
How do I fix it?
I would just add width: 100%; to your image
May be it will be your solution code:
<div class="container-fluid">
<div class="row">
<div class="col-md-7">
<img src="http://placehold.it/550x350" class="img-responsive" style="width:100%" alt="Image">
</div>
<div class="col-md-5">
<h2>How do you auto-resize a large image so that it will fit into a smaller width div container whilst maintaining it's width:height ratio?</h2>
<p>How do you auto-resize a large image so that it will fit into a smaller width div container whilst maintaining it's width:height ratio?</p>
</div>
</div>
</div>
You're not using bootstrap classes for sm and xs screens, use that as well as change the img from max-width to width.
img{
width :100%;
}
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-7">
<img src="http://placehold.it/550x350" class="img-responsive">
</div>
<div class="col-xs-12 col-sm-12 col-md-5">
<h2>How do you auto-resize a large image so that it will fit into a smaller width div container whilst maintaining it's width:height ratio?</h2>
<p>How do you auto-resize a large image so that it will fit into a smaller width div container whilst maintaining it's width:height ratio?</p>
</div>
.img-responsive {
margin: 0 auto;
}
Try adding custom styling
Related
I have let my user select an image preview in div, and then crop an area to upload an image.
Now I have a problem with how to show the image's actual size in a div with Tailwind-CSS.
For example, a.jpg size is 3000px X 2500px.
<body class="antialiased">
<div class="w-2/3 mx-auto">
<div class="relative overflow-auto">
<img src="/a.jpg" class="w-full" alt="">
</div>
</div>
</body>
The size of the image is reduced to fit inside the div, so overflow-auto didn't work.
I want to show both x and y scrollbars, can anyone help?
Thank you.
Apply h-max and w-max to the image's container. This way, your container will always scale according to the image's width and height.
Example:
<body class="antialiased">
<div class="h-max w-max">
<img src="https://s1.1zoom.me/big3/371/363095-commander06.jpg"/>
</div>
</body>
Tailwind-play
If you don't want to change your layout, you can create another separate container for the h-max and w-max utilities:
<body class="antialiased">
<div class="mx-auto w-2/3">
<div class="overflow-auto">
<div class="h-max w-max">
<img src="https://s1.1zoom.me/big3/371/363095-commander06.jpg" />
</div>
</div>
</div>
</body>
Tailwind-play
You can also limit the area by adding custom width and height to the middle container:
<body class="antialiased">
<div class="mx-auto w-2/3">
<div class="overflow-auto h-[300px] w-[500px]">
<div class="h-max w-max">
<img src="https://s1.1zoom.me/big3/371/363095-commander06.jpg" />
</div>
</div>
</div>
</body>
Tailwind-play
How to make image inside div not to be bigger than the div? now I set width is set to 500px what is not a good solution.
<div class="container">
<div class="row row-offcanvas row-offcanvas-right">
<div class="col-md-12 col-lg-12 col-sm-12 col-xm-12">
<div class="col-md-6 col-lg-6 col-sm-12 col-xm-12"">
<img src="imagesource" class="img-responsive" width="500" height="auto">
</div>
</div>
</div>
</div>
Setting
img {
width:100%;
}
or
<img style="width:100%;"/>
will make sure that an img is never wider than its parent container.
You should remove your inline styles (width and height) for <img>. Also remove double quotes here col-xm-12"">
Jsfiddle here
How to set the CSS styles of the images so that it can fit the full width available by bootstrap 6 columns and scale the height accordingly
<div class="col-xs-6">
<img src="the_image.jpg" class="my_image_style">
</div>
Thanks!
You can use the boostrap img-responsive class.
<div class="row">
<div class="col-xs-6">
<img src="http://placehold.it/1000x100" class="img-responsive">
</div>
</div>
Here is a sample bootply
I've a fluid row in which i have a item (nontext) and I want to align it horizontal centered
text
<div class="container-fluid">
<div class="row-fluid">
<div class="span12" style="text-align: center">
<img src="#Url.Content("~/Images/Domain/IMG_1710.jpg")" />
</div>
</div>
</div>
this works pretty fine
but as soon as I add a max-width and max-height the alignment doesn't work anymore.
<div class="container-fluid">
<div class="row-fluid">
<div class="span12" style="text-align: center;max-height: 300px; max-width: 400px" >
<img src="#Url.Content("~/Images/Domain/IMG_1710.jpg")" />
</div>
</div>
What am I doing wrong ? How can I set max width and hight and have a centered alignment?
To follow bootstrap rules, try to center it with the offset class
<div class="row-fluid">
<div class="span4 offset4">
<img src="yourimage" />
</div>
</div>
see documentation
Applying max-height and max-width on one of Bootstrap's span# classes will override grid styling. I would recommend adding the height/width on the image (if the text align doesn't work, you can try margin: 0 auto on the image.
I have a grid something like this:
<div class="container">
<div class="item">
Some Content
</div>
<div class="item">
Some Content
</div>
<div class="item">
Some Content
</div>
<div class="item">
Some Content
</div>
<div class="item">
Some Content
</div>
<div class="item">
Some Content
</div>
</div>
And CSS like this
.container{
width:100%;
}
.item{
width:33%;
float:left;
min-width:150px
}
What happens in this situation is that if the container is bigger than 450 pixels you get three columns and two rows. If the container's width reduces to below 450px you end up two columns and three rows and the items are forced to 150px width.
The problem is that there is unsightly whitespace to the right of the second item.
I would like to make it so that the items always fill the container's width. Is this possible?
Have you tried jQuery Masonry? I think that it's the best solution to your problem: jquery masonry