Reputation: 6197
here is the fiddle:
<div style="background-color: yellow;">
<div style="background-color: red; float: left;">1</div>
<div style="background-color: green; float: left;"><img src="http://static.idokep.hu/images/nagyelore/ujikon2/030.png" width="108" height="50" /></div>
</div>
I know the goal can be achieved by adding "line-height: 50" to the first div (not done in the fiddle). But lets suppose I can variate the height many times and I dont want to set the lineheight too. Can it be somehow 100%?
Upvotes: 0
Views: 158
Reputation: 9065
You need to add vertical-align: middle
. Changed structure a little bit:
.text {
background-color: red;
display: inline;
vertical-align: middle;
}
img {
vertical-align: middle;
}
<div style="background-color: yellow;">
<div class="text">1</div>
<img src="http://static.idokep.hu/images/nagyelore/ujikon2/030.png" width="108" height="50" />
</div>
Upvotes: 3
Reputation: 1322
#wrapper {
display:table-row;
}
#text {
display:table-cell;
float:none !important;
height:100px;
vertical-align:middle;
}
#pic {
display:table-cell;
float:none !important;
vertical-align:middle;
}
$(document).ready(function() {
var picHeight = $("#pic").outerHeight();
$("#text").css({"height": picHeight, "line-height":picHeight+"px"});
});
Upvotes: 1