如何调整图像大小以适合显示:flex child divs?请参阅此插件:http://plnkr.co/edit/zqdpqnV7QkKrx7lm1Tsi?p=preview
我想要缩放的图片是:http://images.freeimages.com/images/previews/8fe/sky-above-the-black-mountains-1402912.jpg
我在Stackoverflow上读到这可以使用max-height和max-width属性来完成,但我无法达到预期的结果。
我也读过这篇文章,但它没有帮助:http://www.w3schools.com/css/css_rwd_images.asp
CSS:
.card {
position: relative;
z-index: 2;
box-shadow: 0 0.1rem 0.2rem #aaa;
background: #fff;
border-radius: 0.2rem;
margin: 0.5rem 0 1rem 0;
height: 10rem;
display: flex;
flex-direction: column;
}
.card.sm {
height: 10rem;
}
.card.sm .card-action {
padding: 0.5rem;
}
.card.md {
height: 20rem;
}
.card.md .card-action {
padding: 1rem;
}
.card.lg {
height: 30rem;
}
.card.lg .card-action {
padding: 1.5rem;
}
.card .card-content {
padding: 1rem;
flex: 8;
overflow:auto;
overflow-y: scroll;
}
.card .card-content .card-title {
font-weight: bold;
font-size: 1.1rem;
}
.card .card-action {
flex: 2;
max-height: 5%;
padding: 1rem;
border-top: 0.1rem solid rgba(160, 160, 160, 0.2);
text-transform: uppercase;
}
.card .card-image {
position: relative;
flex: 24;
overflow:hidden;
}
.card .card-image img {
border-radius: 2px 2px 0 0;
position: relative;
left: 0;
right: 0;
top: 0;
bottom: 0;
max-width: 100%;
max-height: 100%;
}
HTML:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
<div style="width:30rem">
<div class="card md">
<div class="card-image">
<img src="http://images.freeimages.com/images/previews/8fe/sky-above-the-black-mountains-1402912.jpg"/>
</div>
<div class="card-content">
<span class="card-title">Title</span>
<p>Some content</p>
</div>
<div class="card-action">
<a href="#">ACTION 1</a>
<a href="#">ACTION 2</a>
</div>
<div class="card-action">
<a href="#">ACTION 3</a>
<a href="#">ACTION 4</a>
</div>
</div>
</div>
<div style="width:30rem">
<div class="card md">
<div class="card-content">
<span class="card-title">Title</span>
<p>Some content</p>
</div>
<div class="card-action">
<a href="#">ACTION 1</a>
<a href="#">ACTION 2</a>
</div>
<div class="card-action">
<a href="#">ACTION 3</a>
<a href="#">ACTION 4</a>
</div>
</div>
</div>
</body>
</html>