Is it posible to set a SVG Image with a min-width in %? because its not working for me. The same for an Image. Both are set to fit 100% of the containing div. When i resize my browser i want the image to stop resizing when it reaches a min-width.
是否可以设置最小宽度为%的SVG图像?因为它不适合我。对于图像也是如此。两者都设置为适合包含div的100%。当我调整浏览器的大小时,我希望图像在达到最小宽度时停止调整大小。
html
<div id="first">
<img href="" alt="si"/>
</div>
css
#first{
background-color:black;
width:100%;
height:30%;
position:fixed;
overflow:hidden;
}
#first img{
width:100%;
min-width:50%;
}
2 个解决方案
#1
The %
is relative to width of parent div
, And for outer most div
it is relative to browser's width.
%相对于父div的宽度,而对于最外面的div,它相对于浏览器的宽度。
Suppose you want that image should not get smaller than 200px, use script below
假设您希望该图像不应小于200px,请使用下面的脚本
#first img{
width:100%;
min-width:200px;
}
Here if #first
width is greater than 200px than image scales or remains 200px min.
如果#first宽度大于200px而不是图像比例或保持200px min。
#2
first
is a parent to your image and its width is width:100%
. However, your image's minimum width is 50% and the percent values are relative to the parent element, so your preference is not quite possible under these circumstances.
first是图像的父级,宽度为宽度:100%。但是,图像的最小宽度为50%,百分比值相对于父元素,因此在这些情况下您的偏好不太可能。
#1
The %
is relative to width of parent div
, And for outer most div
it is relative to browser's width.
%相对于父div的宽度,而对于最外面的div,它相对于浏览器的宽度。
Suppose you want that image should not get smaller than 200px, use script below
假设您希望该图像不应小于200px,请使用下面的脚本
#first img{
width:100%;
min-width:200px;
}
Here if #first
width is greater than 200px than image scales or remains 200px min.
如果#first宽度大于200px而不是图像比例或保持200px min。
#2
first
is a parent to your image and its width is width:100%
. However, your image's minimum width is 50% and the percent values are relative to the parent element, so your preference is not quite possible under these circumstances.
first是图像的父级,宽度为宽度:100%。但是,图像的最小宽度为50%,百分比值相对于父元素,因此在这些情况下您的偏好不太可能。