简体   繁体   English

将最大宽度,最大高度与宽度,高度结合使用

[英]Use of max-width, max-height in combination with width, height

I beginning to learn css, and I am writing code based on a course am watching. 我开始学习CSS,并且正在根据观看的课程编写代码。 The author has written the style for left bar images to look like this: 作者编写了左栏图像的样式,如下所示:

.left-side img{
width: 100%;
height: 100%;
max-width: 140px;
max-height: 140px;
}

What's the use of width: 100% and height: 100%. 宽度:100%和高度:100%的用途是什么。 Removing them seems to not have any effect. 删除它们似乎没有任何效果。

The current image has original size of 32x32 pixels, you can replace the same image with other image of 512x512px, 当前图片的原始尺寸为32x32像素,您可以将同一图片替换为其他512x512px的图片,

width: 100% - no matter, what is the actual width of image, stretch it to 100% width of parent container width: 100% -不管图像的实际宽度是多少,将其拉伸到父容器的100%宽度

height: 100%; - no matter, what is the actual height of image, stretch it to 100% height of parent container -没关系,图片的实际高度是多少,将其拉伸到父容器的100%高度

max-width: 140px; - if image is big, limit it to this value or if smaller, width100% will stretch it till 140px -如果图片较大,请将其限制为该值;如果图片较小,则width100%会将其拉伸到140px

max-height: 140px; - if image is big , limit it to this value or if smaller, height100% will stretch it till 140px -如果图片较大,请将其限制为该值;如果图片较小,则height100%会将其拉伸到140px

 .left-side img { width: 100%; height: 100%; max-width: 140px; max-height: 140px; } 
 <h1>image: 32X32</h1> <div class="left-side"> <img src="https://cdn0.iconfinder.com/data/icons/social-flat-rounded-rects/512/instagram-32.png" alt="32X32" title="32X32"> </div> <hr> <h1>image: 512X512</h1> <div class="left-side"> <img src="https://cdn0.iconfinder.com/data/icons/social-flat-rounded-rects/512/instagram-512.png" alt="512X512" title="512X512"> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM