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 trialStavros Sofroniadis
Front End Web Development Techdegree Student 360 PointsDifferences between min-height and height
Dear Friends,
Dont understand what is the difference between min-height and height attribute. The same form max-height and height.
As from experience when we strucure an image <img src="photos/header.png" alt="information" class="header_image">
Then apply css as follows:
.header_image{ height:200px; width:100%; }
The image will cover 100% of width of page and will be 200px height.
But dont undserstand what is the diffrence with max or min-height
Respectevely dont undewrstand the diffrence with min or max-width in relation with width
Thank You,
5 Answers
Steven Parker
231,269 PointsA simple "min-" or "max-" value is a limit, but the element can be stretch or shrink based on other factors (like window size).
But a pure "width" or "height" is an exact value, and the element will be exactly that size no matter how big the window is.
For more details, see the related MDN pages (like min-width).
Stavros Sofroniadis
Front End Web Development Techdegree Student 360 PointsFor simple "width" and "height" it is that you mentioned, it is the exact "width" or "height" of an element.(ex: div , img etc)
For min or max value you mean that we set the limit of an element. For instance if we set for an img element
img{ min-width:200px; min-height:200px; } The above mean that the img could not be less than 200px (in height and width)? Do we know the exact dimensions of the image if we dont set simple width and height but only min-height & min-width?
or if we set for the same img max-width & max-height as follows:
img{ max-height:200px; max-width:1200px; }
Suppose the above means that the image should not have height more than 200px and should not have width more than 1200px? Again, we have set the top limit dimensions of an image , but we dont know the exact dimensions of an image.
Steven Parker
231,269 PointsEvery image has a size, and will be displayed unaltered unless the CSS requires it to be changed. Examine the image file itself to see the exact dimensions. On Windows, you can just hover the cursor over the file in the Explorer and it will show the dimensions in a pop-up.
Stavros Sofroniadis
Front End Web Development Techdegree Student 360 PointsThank You,
so the image has some specific diminesions when we place it into html document and just with min or max values we set minimim-maxium (height or wifth) should have .
What happens if we have set for an img:
img{ max-height:200px; max-width:500px; }
and after we shrinked a computer screen to half the dimension of the img decreased to half. That is height:100px: and width:250px;
or the image dimensons will not fall under 200px in height & 500px in width?
Steven Parker
231,269 PointsThe "max-" value is an upper limit. The dimension can never be more than that, but it can be less.
And an image can be "clipped" (cut off) instead of shrunk on a small screen. To make it shrink, you'd also need some other setting (like "width: 100%
").
Stavros Sofroniadis
Front End Web Development Techdegree Student 360 PointsThe same apliees for "min" - value. That is lower limit and if you have an image with default width:400px set min-width:200px then if you shrink the browser window then the image will not have lower width dimension than 200px? Have mentioned a video from browser page shrikage and expansion. https://photos.app.goo.gl/YBUe7vx5majf5Fpv9
Just to have better understanding what i mean,
When you mean to clip an image, it is to crop an image ?
If you dont set an image width:100% and have an image with min-width:200px and shrink the browser window then the image will not became lower from it's default width?
Steven Parker
231,269 Points"Crop" is another term that also means "cut off". And yes, browser size won't affect an image unless the image has settings (percentage width would be one example) that make it responsive.
Stavros Sofroniadis
Front End Web Development Techdegree Student 360 PointsTo make shrink an image what is the diffrence with croping and image? Little confuse the diffrences between these 2 terms.
Therefore, if you have an image with default width:500px; set for an image: img{ width:100%; max-width:500px; min-width:50px; }
then you make responsive the image?
if make smaller the browser window, then the image width will not fall under 50px?
: In other image example, if you have an image with default width:200px. And after apply the following css style to the image:
img{ width:200px; max-width:400px; min-width:100px; }
If you make smaller the browser window , then the image will never fall under 100px(width) and also when fully expand browser window then the image will have width:200px (as defined in width). The image may have more than 200px width in case you view the page in larger computer screens? (let say for 32 inch computer screens)
Steven Parker
231,269 PointsCropping (or clipping) is "cutting off", instead of shrinking.
If an image is set with "width:200px
", it will always be 200px, no matter what the window size. The "min-" and "max-" settings will not be used.
As I said before, to make an image responsive to window size, it must have a setting such as a percentage width, like in your original example.