c = (m × aw) / (ah × 3)
w1 = 2/3 × (100% − m) + c
w2 = 1/3 × (100% − m) − c
複製代碼
<!--html-->
<div class="thumbnails">
<img src="https://placeimg.com/400/300/animals" alt="A randomly selected animal photo">
<img src="https://placeimg.com/400/300/nature" alt="A randomly selected nature photo">
<img src="https://placeimg.com/400/300/arch" alt="A randomly selected archirecture photo">
</div>
<!--scss-->
// Using values from the original design
$margin: 20px;
$aspect-width: 4;
$aspect-height: 3;
// Calculate c
$constant: ($margin * $aspect-width) / ($aspect-height * 3);
.thumbnails {
width: 50%;
margin: 0 auto;
padding: $margin;
border: 2px solid black;
overflow: hidden; // crude clearfix
// First image becomes big one on left
> *:first-child {
display: block;
float: left;
margin-right: $margin;
// Magic formula!
width: calc( (2 / 3 * (100% - #{$margin}) ) + #{$constant} );
}
// 2nd & 3rd images become smaller ones
// on right
> *:nth-child(n + 2) {
display: block;
float: right;
// Magic formula!
width: calc( (1 / 3 * (100% - #{$margin}) ) - #{$constant} );
}
// 3rd image also has top margin
> *:nth-child(3) {
margin-top: $margin;
}
}
複製代碼