In my project, there are two columns. The left contains an image that is, at maximum, 100% of the left column's width with an auto height. The right varies in width while the left one fills up the remaining space. This uses the technique described in JackJoe's answer to a previous question.
What I want to do now is vertically center the column with the smaller height. There are times when the right column or the left column is shorter, depending upon the width of the window. I have tried using
{
position: relative;
top: 50%;
transform: translateY(-50%); //with more prefixes
}
However, for some reason the top: 50%
part does not work at all. Here is my current code, without the vertical centering attempt (this works as expected):
$(document).ready(function() {
$("#right").click(function() {
$(this).toggleClass("wide");
});
});
#container {
width: 100%;
border: 1px solid red;
height: auto;
overflow: hidden;
}
#right {
float: right;
border: 1px solid green;
width: 100px;
transition: 1s width;
}
#left {
border: 1px solid green;
width: auto;
overflow: hidden;
}
#left img {
max-width: 100%;
height: auto;
}
#right.wide {
width: 300px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="container">
<div id="right">
Click Me
</div>
<div id="left">
<img src="http://placehold.it/440x120"/>
</div>
</div>
EDIT: I forgot to specify -- the width of the right column needs to depend upon the widths of it's contents, just like the width of an inline-block element element would with no set width. I just used exact widths in the demo to show the fluidity of the columns.