Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Konrad Pilch
Konrad Pilch
2,435 Points

How can i make my height and width..

Hi,

I have a situation that i believe its attendable.

So what im trying to do it to have my image thats 100%(300px) width and like 300px height and when you resize the browser to a macbook , tablet, mobile, the image will be allways square and the height willl change. I tried many things but i believe its has to do with JS ?

1 Answer

Hi Konrad,

Define max-width 100% in your CSS. This way, the image will automatically resize depending on the browser window. So it will work on all screen sizes etc. I think this code might be a solution for you:

img {
    max-width: 100%;
    height: auto;
}
Konrad Pilch
Konrad Pilch
2,435 Points

HI, thank yo for reply.

Oh , i forget to tell you that i add it with CSS and i have to display the height otherwise it wont appear .

I tried that many times and a lot of other things too . I see quite often , maybe? sites like that but i cant find any solution for it .