Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make image responsive inside a div

My code is as Follows:

<div class="abc">
    <div class="bcd">
        <a href="#">
            <img class="img1" width="50" height="50"/>
        </a>
        <a>
            <h3>Some Text</h3>
        </a> 
    </div>
    <div class="bcd">
        <a href="#">
            <img class="img1" width="50" height="50"/>
        </a>
        <a>
            <h3>Some Text</h3>
        </a> 
    </div>
    <div class="bcd">
        <a href="#">
            <img class="img1" width="50" height="50"/>
        </a>
        <a>
            <h3>Some Text</h3>
        </a> 
    </div>
    <div class="bcd">
        <a href="#">
            <img class="img1" width="50" height="50"/>
        </a>
        <a>
            <h3>Some Text</h3>
        </a> 
    </div>
</div>

How can I make the image responsive for Mobile(360X640px) and iPad(768X1024px)? Can you please give me the CSS Code?

I have to give two Images in Mobile and Four in iPad in one line!!

like image 509
Kusumakar Pant Avatar asked Jul 11 '14 10:07

Kusumakar Pant


People also ask

How do I force an image to fit in a div?

To auto-resize an image or a video to fit in a div container use object-fit property. It is used to specify how an image or video fits in the container. object-fit property: This property is used to specify how an image or video resize and fit the container.

What CSS code will make an image responsive?

Using CSS “max-width” Property The most commonly used CSS property to make an Image responsive is the max-width property. You can set the value as 100%. You can do this inline by using the style attribute on each image.


3 Answers

Here is the code you need to follow :

img {
    max-width: 100%;
    height: auto;
    }

Refer : http://html5hub.com/html5-picture-element/

like image 182
Sulthan Allaudeen Avatar answered Oct 18 '22 22:10

Sulthan Allaudeen


Remove width and height attribute from img tag and add in CSS file for this image max-width:100%; width:100%;

like image 4
Anon Avatar answered Oct 18 '22 22:10

Anon


this setting the image you want to set as a background image in a div and give set the background size as cover

background-image: url('YOUR URL');
background-size: cover;
like image 4
Naseeruddin V N Avatar answered Oct 18 '22 21:10

Naseeruddin V N