How to make all images fit/same size inside div & responsive
Image:(https://i.stack.imgur.com/VAGy0.jpg)1
All my images has a different size (width/height)
I want to make all my images fit & Responsive inside div even the size of width:100%+
i can use overflow:hidden
to hide some parts, but I want to keep it all same height
to make it equal and still responsive! like height is auto (height:auto
)
I want to use this code <div><img src=".."/></div>
I don't want to use/change code to style background: url('..');
or any flex
or any object-fit:...;
or use any javascript
Image:(https://i.stack.imgur.com/Ltuef.jpg)2
Image:(https://i.stack.imgur.com/7VFFP.jpg)3
body,
html {
background: #9b9;
}
img {
max-width: 100%;
height: auto;
width: auto;
max-height: auto;
position: relative;
vertical-align: middle;
left: 50%;
transform: translate(-50%);
}
div {
width: 20%;
height: auto;
min-height: 100%;
overflow: hidden;
position: relative;
display: inline-block;
}
<div>
<img src="https://placekitten.com/g/400/500"> Text(1)
</div>
<div>
<img src="https://justifiedgrid.com/wp-content/gallery/life/biking/137646854.jpg"> Text(2)
</div>
<div>
<img src="http://centraltibetanreliefcommittee.org/doh/photo-gallery/good-sliders/MenuCool5/images/image-slider-1.jpg"> Text(3)
</div>
<div>
<img src="https://www.aussiespecialist.com/content/asp/en/sales-resources/image-and-video-galleries/_jcr_content/mainParsys/hero/image.adapt.1663.medium.jpg"> Text(4)
</div>
html css image css3
add a comment |
Image:(https://i.stack.imgur.com/VAGy0.jpg)1
All my images has a different size (width/height)
I want to make all my images fit & Responsive inside div even the size of width:100%+
i can use overflow:hidden
to hide some parts, but I want to keep it all same height
to make it equal and still responsive! like height is auto (height:auto
)
I want to use this code <div><img src=".."/></div>
I don't want to use/change code to style background: url('..');
or any flex
or any object-fit:...;
or use any javascript
Image:(https://i.stack.imgur.com/Ltuef.jpg)2
Image:(https://i.stack.imgur.com/7VFFP.jpg)3
body,
html {
background: #9b9;
}
img {
max-width: 100%;
height: auto;
width: auto;
max-height: auto;
position: relative;
vertical-align: middle;
left: 50%;
transform: translate(-50%);
}
div {
width: 20%;
height: auto;
min-height: 100%;
overflow: hidden;
position: relative;
display: inline-block;
}
<div>
<img src="https://placekitten.com/g/400/500"> Text(1)
</div>
<div>
<img src="https://justifiedgrid.com/wp-content/gallery/life/biking/137646854.jpg"> Text(2)
</div>
<div>
<img src="http://centraltibetanreliefcommittee.org/doh/photo-gallery/good-sliders/MenuCool5/images/image-slider-1.jpg"> Text(3)
</div>
<div>
<img src="https://www.aussiespecialist.com/content/asp/en/sales-resources/image-and-video-galleries/_jcr_content/mainParsys/hero/image.adapt.1663.medium.jpg"> Text(4)
</div>
html css image css3
1
Your div and img both have height auto. Give div required height and add image height to 100%.
– Bidhan Majhi
Nov 25 '18 at 9:34
thanks, I just addheight:300px
to div (required) , I addheight:100%
to img. But It show me something like this ( Code Sample: jsfiddle.net/packy/m2hof8nq/1 , Image Sample: i.stack.imgur.com/7VFFP.jpg ) I want to make my div responsive show like a right side of my image sample
– itti
Nov 25 '18 at 10:16
add a comment |
Image:(https://i.stack.imgur.com/VAGy0.jpg)1
All my images has a different size (width/height)
I want to make all my images fit & Responsive inside div even the size of width:100%+
i can use overflow:hidden
to hide some parts, but I want to keep it all same height
to make it equal and still responsive! like height is auto (height:auto
)
I want to use this code <div><img src=".."/></div>
I don't want to use/change code to style background: url('..');
or any flex
or any object-fit:...;
or use any javascript
Image:(https://i.stack.imgur.com/Ltuef.jpg)2
Image:(https://i.stack.imgur.com/7VFFP.jpg)3
body,
html {
background: #9b9;
}
img {
max-width: 100%;
height: auto;
width: auto;
max-height: auto;
position: relative;
vertical-align: middle;
left: 50%;
transform: translate(-50%);
}
div {
width: 20%;
height: auto;
min-height: 100%;
overflow: hidden;
position: relative;
display: inline-block;
}
<div>
<img src="https://placekitten.com/g/400/500"> Text(1)
</div>
<div>
<img src="https://justifiedgrid.com/wp-content/gallery/life/biking/137646854.jpg"> Text(2)
</div>
<div>
<img src="http://centraltibetanreliefcommittee.org/doh/photo-gallery/good-sliders/MenuCool5/images/image-slider-1.jpg"> Text(3)
</div>
<div>
<img src="https://www.aussiespecialist.com/content/asp/en/sales-resources/image-and-video-galleries/_jcr_content/mainParsys/hero/image.adapt.1663.medium.jpg"> Text(4)
</div>
html css image css3
Image:(https://i.stack.imgur.com/VAGy0.jpg)1
All my images has a different size (width/height)
I want to make all my images fit & Responsive inside div even the size of width:100%+
i can use overflow:hidden
to hide some parts, but I want to keep it all same height
to make it equal and still responsive! like height is auto (height:auto
)
I want to use this code <div><img src=".."/></div>
I don't want to use/change code to style background: url('..');
or any flex
or any object-fit:...;
or use any javascript
Image:(https://i.stack.imgur.com/Ltuef.jpg)2
Image:(https://i.stack.imgur.com/7VFFP.jpg)3
body,
html {
background: #9b9;
}
img {
max-width: 100%;
height: auto;
width: auto;
max-height: auto;
position: relative;
vertical-align: middle;
left: 50%;
transform: translate(-50%);
}
div {
width: 20%;
height: auto;
min-height: 100%;
overflow: hidden;
position: relative;
display: inline-block;
}
<div>
<img src="https://placekitten.com/g/400/500"> Text(1)
</div>
<div>
<img src="https://justifiedgrid.com/wp-content/gallery/life/biking/137646854.jpg"> Text(2)
</div>
<div>
<img src="http://centraltibetanreliefcommittee.org/doh/photo-gallery/good-sliders/MenuCool5/images/image-slider-1.jpg"> Text(3)
</div>
<div>
<img src="https://www.aussiespecialist.com/content/asp/en/sales-resources/image-and-video-galleries/_jcr_content/mainParsys/hero/image.adapt.1663.medium.jpg"> Text(4)
</div>
body,
html {
background: #9b9;
}
img {
max-width: 100%;
height: auto;
width: auto;
max-height: auto;
position: relative;
vertical-align: middle;
left: 50%;
transform: translate(-50%);
}
div {
width: 20%;
height: auto;
min-height: 100%;
overflow: hidden;
position: relative;
display: inline-block;
}
<div>
<img src="https://placekitten.com/g/400/500"> Text(1)
</div>
<div>
<img src="https://justifiedgrid.com/wp-content/gallery/life/biking/137646854.jpg"> Text(2)
</div>
<div>
<img src="http://centraltibetanreliefcommittee.org/doh/photo-gallery/good-sliders/MenuCool5/images/image-slider-1.jpg"> Text(3)
</div>
<div>
<img src="https://www.aussiespecialist.com/content/asp/en/sales-resources/image-and-video-galleries/_jcr_content/mainParsys/hero/image.adapt.1663.medium.jpg"> Text(4)
</div>
body,
html {
background: #9b9;
}
img {
max-width: 100%;
height: auto;
width: auto;
max-height: auto;
position: relative;
vertical-align: middle;
left: 50%;
transform: translate(-50%);
}
div {
width: 20%;
height: auto;
min-height: 100%;
overflow: hidden;
position: relative;
display: inline-block;
}
<div>
<img src="https://placekitten.com/g/400/500"> Text(1)
</div>
<div>
<img src="https://justifiedgrid.com/wp-content/gallery/life/biking/137646854.jpg"> Text(2)
</div>
<div>
<img src="http://centraltibetanreliefcommittee.org/doh/photo-gallery/good-sliders/MenuCool5/images/image-slider-1.jpg"> Text(3)
</div>
<div>
<img src="https://www.aussiespecialist.com/content/asp/en/sales-resources/image-and-video-galleries/_jcr_content/mainParsys/hero/image.adapt.1663.medium.jpg"> Text(4)
</div>
html css image css3
html css image css3
edited Nov 25 '18 at 12:52
itti
asked Nov 25 '18 at 9:24
ittiitti
54
54
1
Your div and img both have height auto. Give div required height and add image height to 100%.
– Bidhan Majhi
Nov 25 '18 at 9:34
thanks, I just addheight:300px
to div (required) , I addheight:100%
to img. But It show me something like this ( Code Sample: jsfiddle.net/packy/m2hof8nq/1 , Image Sample: i.stack.imgur.com/7VFFP.jpg ) I want to make my div responsive show like a right side of my image sample
– itti
Nov 25 '18 at 10:16
add a comment |
1
Your div and img both have height auto. Give div required height and add image height to 100%.
– Bidhan Majhi
Nov 25 '18 at 9:34
thanks, I just addheight:300px
to div (required) , I addheight:100%
to img. But It show me something like this ( Code Sample: jsfiddle.net/packy/m2hof8nq/1 , Image Sample: i.stack.imgur.com/7VFFP.jpg ) I want to make my div responsive show like a right side of my image sample
– itti
Nov 25 '18 at 10:16
1
1
Your div and img both have height auto. Give div required height and add image height to 100%.
– Bidhan Majhi
Nov 25 '18 at 9:34
Your div and img both have height auto. Give div required height and add image height to 100%.
– Bidhan Majhi
Nov 25 '18 at 9:34
thanks, I just add
height:300px
to div (required) , I add height:100%
to img. But It show me something like this ( Code Sample: jsfiddle.net/packy/m2hof8nq/1 , Image Sample: i.stack.imgur.com/7VFFP.jpg ) I want to make my div responsive show like a right side of my image sample– itti
Nov 25 '18 at 10:16
thanks, I just add
height:300px
to div (required) , I add height:100%
to img. But It show me something like this ( Code Sample: jsfiddle.net/packy/m2hof8nq/1 , Image Sample: i.stack.imgur.com/7VFFP.jpg ) I want to make my div responsive show like a right side of my image sample– itti
Nov 25 '18 at 10:16
add a comment |
1 Answer
1
active
oldest
votes
body,
html {
background: #9b9;
}
img {
max-width: 100%;
max-height: auto;
position: relative;
vertical-align: middle;
left: 50%;
transform: translate(-50%);
height: 150px;
width: 150px;
object-fit:cover;
}
div {
width: 20%;
height: auto;
min-height: 100%;
overflow: hidden;
position: relative;
display: inline-block;
}
<div>
<img src="https://placekitten.com/g/400/500"> Text(1)
</div>
<div>
<img src="https://justifiedgrid.com/wp-content/gallery/life/biking/137646854.jpg"> Text(2)
</div>
<div>
<img src="http://centraltibetanreliefcommittee.org/doh/photo-gallery/good-sliders/MenuCool5/images/image-slider-1.jpg"> Text(3)
</div>
<div>
<img src="https://www.aussiespecialist.com/content/asp/en/sales-resources/image-and-video-galleries/_jcr_content/mainParsys/hero/image.adapt.1663.medium.jpg"> Text(4)
</div>
Thanks you, Do you have another way if It doesn't use anyobject-fit:...
– itti
Nov 25 '18 at 12:18
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466169%2fhow-to-make-all-images-fit-same-size-inside-div-responsive%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
body,
html {
background: #9b9;
}
img {
max-width: 100%;
max-height: auto;
position: relative;
vertical-align: middle;
left: 50%;
transform: translate(-50%);
height: 150px;
width: 150px;
object-fit:cover;
}
div {
width: 20%;
height: auto;
min-height: 100%;
overflow: hidden;
position: relative;
display: inline-block;
}
<div>
<img src="https://placekitten.com/g/400/500"> Text(1)
</div>
<div>
<img src="https://justifiedgrid.com/wp-content/gallery/life/biking/137646854.jpg"> Text(2)
</div>
<div>
<img src="http://centraltibetanreliefcommittee.org/doh/photo-gallery/good-sliders/MenuCool5/images/image-slider-1.jpg"> Text(3)
</div>
<div>
<img src="https://www.aussiespecialist.com/content/asp/en/sales-resources/image-and-video-galleries/_jcr_content/mainParsys/hero/image.adapt.1663.medium.jpg"> Text(4)
</div>
Thanks you, Do you have another way if It doesn't use anyobject-fit:...
– itti
Nov 25 '18 at 12:18
add a comment |
body,
html {
background: #9b9;
}
img {
max-width: 100%;
max-height: auto;
position: relative;
vertical-align: middle;
left: 50%;
transform: translate(-50%);
height: 150px;
width: 150px;
object-fit:cover;
}
div {
width: 20%;
height: auto;
min-height: 100%;
overflow: hidden;
position: relative;
display: inline-block;
}
<div>
<img src="https://placekitten.com/g/400/500"> Text(1)
</div>
<div>
<img src="https://justifiedgrid.com/wp-content/gallery/life/biking/137646854.jpg"> Text(2)
</div>
<div>
<img src="http://centraltibetanreliefcommittee.org/doh/photo-gallery/good-sliders/MenuCool5/images/image-slider-1.jpg"> Text(3)
</div>
<div>
<img src="https://www.aussiespecialist.com/content/asp/en/sales-resources/image-and-video-galleries/_jcr_content/mainParsys/hero/image.adapt.1663.medium.jpg"> Text(4)
</div>
Thanks you, Do you have another way if It doesn't use anyobject-fit:...
– itti
Nov 25 '18 at 12:18
add a comment |
body,
html {
background: #9b9;
}
img {
max-width: 100%;
max-height: auto;
position: relative;
vertical-align: middle;
left: 50%;
transform: translate(-50%);
height: 150px;
width: 150px;
object-fit:cover;
}
div {
width: 20%;
height: auto;
min-height: 100%;
overflow: hidden;
position: relative;
display: inline-block;
}
<div>
<img src="https://placekitten.com/g/400/500"> Text(1)
</div>
<div>
<img src="https://justifiedgrid.com/wp-content/gallery/life/biking/137646854.jpg"> Text(2)
</div>
<div>
<img src="http://centraltibetanreliefcommittee.org/doh/photo-gallery/good-sliders/MenuCool5/images/image-slider-1.jpg"> Text(3)
</div>
<div>
<img src="https://www.aussiespecialist.com/content/asp/en/sales-resources/image-and-video-galleries/_jcr_content/mainParsys/hero/image.adapt.1663.medium.jpg"> Text(4)
</div>
body,
html {
background: #9b9;
}
img {
max-width: 100%;
max-height: auto;
position: relative;
vertical-align: middle;
left: 50%;
transform: translate(-50%);
height: 150px;
width: 150px;
object-fit:cover;
}
div {
width: 20%;
height: auto;
min-height: 100%;
overflow: hidden;
position: relative;
display: inline-block;
}
<div>
<img src="https://placekitten.com/g/400/500"> Text(1)
</div>
<div>
<img src="https://justifiedgrid.com/wp-content/gallery/life/biking/137646854.jpg"> Text(2)
</div>
<div>
<img src="http://centraltibetanreliefcommittee.org/doh/photo-gallery/good-sliders/MenuCool5/images/image-slider-1.jpg"> Text(3)
</div>
<div>
<img src="https://www.aussiespecialist.com/content/asp/en/sales-resources/image-and-video-galleries/_jcr_content/mainParsys/hero/image.adapt.1663.medium.jpg"> Text(4)
</div>
body,
html {
background: #9b9;
}
img {
max-width: 100%;
max-height: auto;
position: relative;
vertical-align: middle;
left: 50%;
transform: translate(-50%);
height: 150px;
width: 150px;
object-fit:cover;
}
div {
width: 20%;
height: auto;
min-height: 100%;
overflow: hidden;
position: relative;
display: inline-block;
}
<div>
<img src="https://placekitten.com/g/400/500"> Text(1)
</div>
<div>
<img src="https://justifiedgrid.com/wp-content/gallery/life/biking/137646854.jpg"> Text(2)
</div>
<div>
<img src="http://centraltibetanreliefcommittee.org/doh/photo-gallery/good-sliders/MenuCool5/images/image-slider-1.jpg"> Text(3)
</div>
<div>
<img src="https://www.aussiespecialist.com/content/asp/en/sales-resources/image-and-video-galleries/_jcr_content/mainParsys/hero/image.adapt.1663.medium.jpg"> Text(4)
</div>
body,
html {
background: #9b9;
}
img {
max-width: 100%;
max-height: auto;
position: relative;
vertical-align: middle;
left: 50%;
transform: translate(-50%);
height: 150px;
width: 150px;
object-fit:cover;
}
div {
width: 20%;
height: auto;
min-height: 100%;
overflow: hidden;
position: relative;
display: inline-block;
}
<div>
<img src="https://placekitten.com/g/400/500"> Text(1)
</div>
<div>
<img src="https://justifiedgrid.com/wp-content/gallery/life/biking/137646854.jpg"> Text(2)
</div>
<div>
<img src="http://centraltibetanreliefcommittee.org/doh/photo-gallery/good-sliders/MenuCool5/images/image-slider-1.jpg"> Text(3)
</div>
<div>
<img src="https://www.aussiespecialist.com/content/asp/en/sales-resources/image-and-video-galleries/_jcr_content/mainParsys/hero/image.adapt.1663.medium.jpg"> Text(4)
</div>
answered Nov 25 '18 at 11:26
Dogukan CavusDogukan Cavus
2,4771423
2,4771423
Thanks you, Do you have another way if It doesn't use anyobject-fit:...
– itti
Nov 25 '18 at 12:18
add a comment |
Thanks you, Do you have another way if It doesn't use anyobject-fit:...
– itti
Nov 25 '18 at 12:18
Thanks you, Do you have another way if It doesn't use any
object-fit:...
– itti
Nov 25 '18 at 12:18
Thanks you, Do you have another way if It doesn't use any
object-fit:...
– itti
Nov 25 '18 at 12:18
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466169%2fhow-to-make-all-images-fit-same-size-inside-div-responsive%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Your div and img both have height auto. Give div required height and add image height to 100%.
– Bidhan Majhi
Nov 25 '18 at 9:34
thanks, I just add
height:300px
to div (required) , I addheight:100%
to img. But It show me something like this ( Code Sample: jsfiddle.net/packy/m2hof8nq/1 , Image Sample: i.stack.imgur.com/7VFFP.jpg ) I want to make my div responsive show like a right side of my image sample– itti
Nov 25 '18 at 10:16