Is it possible to centre text using CSS horizontally and vertically within a div that also has a variable size image (which should always be right-aligned)?
For example, this is to style the "header" of a sports league table display - with the header basically consisting of the league name (the text) and optionally a league logo (the image). The image width and height could be variable, depending on the logo image used.
.lbo_header_logo {
border: 1px solid #31639C;
float: right;
margin-left: 20px;
vertical-align: middle;
}
.lbo_header_title {
padding: 5px;
background-color: #ddeeff;
border: 1px solid #31639C;
min-width: 550px;
vertical-align: middle;
width: 50%;
}
.lbo_header_name {
color: black;
font-size: 16px;
font-weight: bold;
overflow: hidden;
text-align: center;
vertical-align: middle;
}
<html>
<head>
<title>Test!!</title>
</head>
<body>
<div class="lbo_header_title">
<div class="lbo_header_name">League 1<IMG class="lbo_header_logo" src="images/logo1.gif" width="70" height="30"></div>
</div>
<div class="lbo_header_title">
<div class="lbo_header_name">League 2<IMG class="lbo_header_logo" src="images/logo2.gif" width="30" height="70"></div>
</div>
</body>
</html>
I think I've managed to get the text centred horizontally (as per the example), but have struggled vertically!
I've tried all manner of hacks, such as the line-height trick - but this doesn't work for me as the height of the image is unknown.
I guess I'd be looking for some sort of solution that uses a max value for the image height, as ultimately I'd want to limit the logo to a sensible height/width anyway (i.e. to avoid them uploading a stupidly long/wide image that screws up the display anyway!).