You can use :nth-child(n), :nth-last-child(n)and :only-childto target certain items, depending on how many brothers and sisters they have. They are supported in IE9. You can also get the full width if there are two elements in the sample.
HTML
<div class="wrapper">
<div>a</div>
</div>
<div class="wrapper">
<div>a</div>
<div>c</div>
</div>
<div class="wrapper">
<div>a</div>
<div>b</div>
<div>c</div>
</div>
<div class="wrapper">
<div>a</div>
<div>b</div>
<div>c</div>
<div>d</div>
</div>
CSS
.wrapper {
width: 80%;
margin: 1em auto;
overflow: hidden;
}
.wrapper div {
float: left;
width: 50%;
min-height: 100px;
}
.wrapper div:nth-child(1) {
background: #f66;
width: 100%;
min-height: 100px;
}
.wrapper div:nth-child(2) {
background: #6f6;
}
.wrapper div:nth-child(3) {
background: #66f;
}
.wrapper div:nth-child(4) {
background: #ff6;
}
.wrapper div:only-child {
width: 100%;
min-height: 200px;
}
.wrapper div:nth-child(2):nth-last-child(1) {
width: 100%;
min-height: 100px;
}
.wrapper div:nth-child(3):nth-last-child(1) {
width: 50%;
min-height: 100px;
}
.wrapper div:nth-child(2):nth-last-child(2) {
width: 50%;
min-height: 100px;
}
.wrapper div:nth-child(1):nth-last-child(4) {
width: 50%;
min-height: 100px;
}
.wrapper div:nth-child(2):nth-last-child(3) {
width: 50%;
min-height: 100px;
}
.wrapper div:nth-child(3):nth-last-child(1) {
width: 50%;
min-height: 100px;
}
Codepen Example
http://codepen.io/goshdarnheck/pen/zGKvWX
source
share