I have a feeling that this might not be possible, but I'm hoping someone will prove me wrong.
I have a parent element of a non-fixed height (although it could be, I don't think it helps). Within it are two children, stacked vertically. The height of the first item is unknowable. I'd like the second item to take up the remaining height.
HTML:
<div class="container">
<a class="snippet" href="#">
<img class="example-image" src="example-image.png">
<div class="snippet-text-section">
<div class="snippet-title">Title for the item - could be one or two lines long</div>
<div class="snippet-text">Rest of the text, filling the remaining space.</div>
</div>
</a>
</div>
CSS:
* {
padding: 0;
margin: 0;
}
.container{
position:relative;
}
.snippet {
display: block;
border-radius: 5px;
background-color: #ddd;
color:black;
overflow:hidden;
}
img {
max-width: 100%;
vertical-align: middle;
display: inline-block;
height:100px;
}
.example-image {
width: 100%;
background-color: #111;
}
.date {
position: absolute;
top: -20px;
background-color: #1b1f52;
font-weight: bold;
padding:0px 2px;
color: white;
}
.snippet-text-section {
padding: 0px 20px 20px 0px;
position: absolute;
top: 0;
width: 100%;
height: 100%;
}
.snippet-title {
margin-bottom: 0;
font-size: 14px;
font-weight: 700;
background-color: rgba(255,0,0,0.8);
color: white;
padding: 0 5px;
border-radius: 0px 5px 0px 0px;
}
.snippet-text {
font-size: 20px;
line-height: 25px;
background-color: rgba(0,0,255,0.8);
color: white;
height: 100%;
padding: 0 5px;
border-radius: 0px 0px 5px 5px;
}
Please note I've looked at a lot of posts on here. Most similar ones deal with the child divs having a horizontal layout. The closest I've come to a solution (and what I'm currently using) is Two vertical divs within a 100% height div where I'm forcing the height of the first child, but it's not ideal.
I'm currently wondering if there's a table-layout solution I've missed...
Update It's 2018 and CSS3 support is everywhere. If you're looking for a solution to this, the answer is flexbox. See the second part of Ktash's answer below.