添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

When width is 100% on image element,image is occupying full screen space on resizing.When max-width
is set to 100% on image element,image is not occupying full screen space.Why there is difference in
Note:image element is not inside any other element.It is just placed inside body tags

Responsive Images

Responsive images will automatically adjust to fit the size of the screen.

Resize the browser window to see the effect:

If the element’s width is greater that the max-width you declared then the max-witdth will prevail. But if the element’s width is less than the declared max-width property then the element assumes its normal width.

You could try this out:
Set the width property of the element then in a media query set a max-width property…

For example, width: 100%; and in a media query, say max-width: 500px; something like that then you will understand it better.
This might be helpful

hi…my doubt here is when 100% width is set on img element…on resizing the screen it is occupying screen space…when we use max-width as 100% ,on resizing the screen it is not occupying entire screen space though it is not inside any element.Can you help me here…below is my code

img { width: 100%;

Responsive Images

Responsive images will automatically adjust to fit the size of the screen.

Resize the browser window to see the effect:

hi…my doubt here is when 100% width is set on img element…on resizing the screen it is occupying screen space…when we use max-width as 100% ,on resizing the screen it is not occupying entire screen space though it is not inside any element.Can you help me here…below is my code

img { width: 100%;

Responsive Images

shashanka:

when we use max-width as 100% ,on resizing the screen it is not occupying entire screen space though it is not inside any element.

That is what i am trying to explain. When you declared, width: 100%, you disregarded the original width of the img and instead made it 100 % of its container-- you could check the img size property if you have it locally on your computer.

So, when u declared it max-width: 100%, the img original width might not be as big as the container, the body in this case.

A more detailed explanation:
Say your img original size is 300px and the body width is 500px. Width: 100% will make the img equal to 500px, disregarding the img original width. On the other hand if you say max-width: 100%. The img will jus be it’s original since it’s not more than 500px, originally. Assuming the img width is, for example, 800px , then max-width will take into effect.

Hope that helps. Tried to explain in English as much as i could.