App*_*cow 2 css image twitter-bootstrap
我有一个600px宽度的图像。
它必须位于宽度为的引导程序col-xs-6或12div 内,300px并且如果屏幕宽度小于,则必须调整其大小300px。
如何在CSS 中使用width和max-width?
我认为这将解决您的问题。
img {
width: 100%;
max-width: 300px;
}
Run Code Online (Sandbox Code Playgroud)
如果 div 宽度大于 300px,图像的最大宽度为 300px。如果 div 小于 300px,图像应填充 div 的 100% 宽度。
只是这样做:
img {
width: 100%;
max-width: 300px;
height: auto;
}
Run Code Online (Sandbox Code Playgroud)