Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The only (and the best cross-browser) way as I know is to use an <code>inline-block</code> helper with <code>height: 100%</code> and <code>vertical-align: middle</code> on both elements.</p> <p>So there is a solution: <a href="http://jsfiddle.net/kizu/4RPFa/4570/" rel="noreferrer">http://jsfiddle.net/kizu/4RPFa/4570/</a></p> <p><div class="snippet" data-lang="js" data-hide="true" data-console="false" data-babel="false"> <div class="snippet-code snippet-currently-hidden"> <pre class="snippet-code-css lang-css prettyprint-override"><code>.frame { height: 25px; /* equals max image height */ width: 160px; border: 1px solid red; white-space: nowrap; /* this is required unless you put the helper span closely near the img */ text-align: center; margin: 1em 0; } .helper { display: inline-block; height: 100%; vertical-align: middle; } img { background: #3A6F9A; vertical-align: middle; max-height: 25px; max-width: 160px; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="frame"&gt; &lt;span class="helper"&gt;&lt;/span&gt;&lt;img src="http://jsfiddle.net/img/logo.png" height=250px /&gt; &lt;/div&gt; &lt;div class="frame"&gt; &lt;span class="helper"&gt;&lt;/span&gt;&lt;img src="http://jsfiddle.net/img/logo.png" height=25px /&gt; &lt;/div&gt; &lt;div class="frame"&gt; &lt;span class="helper"&gt;&lt;/span&gt;&lt;img src="http://jsfiddle.net/img/logo.png" height=23px /&gt; &lt;/div&gt; &lt;div class="frame"&gt; &lt;span class="helper"&gt;&lt;/span&gt;&lt;img src="http://jsfiddle.net/img/logo.png" height=21px /&gt; &lt;/div&gt; &lt;div class="frame"&gt; &lt;span class="helper"&gt;&lt;/span&gt;&lt;img src="http://jsfiddle.net/img/logo.png" height=19px /&gt; &lt;/div&gt; &lt;div class="frame"&gt; &lt;span class="helper"&gt;&lt;/span&gt; &lt;img src="http://jsfiddle.net/img/logo.png" height=17px /&gt; &lt;/div&gt; &lt;div class="frame"&gt; &lt;span class="helper"&gt;&lt;/span&gt; &lt;img src="http://jsfiddle.net/img/logo.png" height=15px /&gt; &lt;/div&gt; &lt;div class="frame"&gt; &lt;span class="helper"&gt;&lt;/span&gt; &lt;img src="http://jsfiddle.net/img/logo.png" height=13px /&gt; &lt;/div&gt; &lt;div class="frame"&gt; &lt;span class="helper"&gt;&lt;/span&gt; &lt;img src="http://jsfiddle.net/img/logo.png" height=11px /&gt; &lt;/div&gt; &lt;div class="frame"&gt; &lt;span class="helper"&gt;&lt;/span&gt; &lt;img src="http://jsfiddle.net/img/logo.png" height=9px /&gt; &lt;/div&gt; &lt;div class="frame"&gt; &lt;span class="helper"&gt;&lt;/span&gt; &lt;img src="http://jsfiddle.net/img/logo.png" height=7px /&gt; &lt;/div&gt; &lt;div class="frame"&gt; &lt;span class="helper"&gt;&lt;/span&gt; &lt;img src="http://jsfiddle.net/img/logo.png" height=5px /&gt; &lt;/div&gt; &lt;div class="frame"&gt; &lt;span class="helper"&gt;&lt;/span&gt; &lt;img src="http://jsfiddle.net/img/logo.png" height=3px /&gt; &lt;/div&gt;</code></pre> </div> </div> </p> <p>Or, if you don't want to have an extra element in modern browsers and don't mind using IE expressions, you can use a pseudo-element and add it to IE using a convenient Expression, that runs only once per element, so there won't be any performance issues:</p> <p>The solution with <code>:before</code> and <code>expression()</code> for IE: <a href="http://jsfiddle.net/kizu/4RPFa/4571/" rel="noreferrer">http://jsfiddle.net/kizu/4RPFa/4571/</a></p> <p><div class="snippet" data-lang="js" data-hide="true" data-console="false" data-babel="false"> <div class="snippet-code snippet-currently-hidden"> <pre class="snippet-code-css lang-css prettyprint-override"><code>.frame { height: 25px; /* equals max image height */ width: 160px; border: 1px solid red; white-space: nowrap; text-align: center; margin: 1em 0; } .frame:before, .frame_before { content: ""; display: inline-block; height: 100%; vertical-align: middle; } img { background: #3A6F9A; vertical-align: middle; max-height: 25px; max-width: 160px; } /* Move this to conditional comments */ .frame { list-style:none; behavior: expression( function(t){ t.insertAdjacentHTML('afterBegin','&lt;span class="frame_before"&gt;&lt;/span&gt;'); t.runtimeStyle.behavior = 'none'; }(this) ); }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="frame"&gt;&lt;img src="http://jsfiddle.net/img/logo.png" height=250px /&gt;&lt;/div&gt; &lt;div class="frame"&gt;&lt;img src="http://jsfiddle.net/img/logo.png" height=25px /&gt;&lt;/div&gt; &lt;div class="frame"&gt;&lt;img src="http://jsfiddle.net/img/logo.png" height=23px /&gt;&lt;/div&gt; &lt;div class="frame"&gt;&lt;img src="http://jsfiddle.net/img/logo.png" height=21px /&gt;&lt;/div&gt; &lt;div class="frame"&gt;&lt;img src="http://jsfiddle.net/img/logo.png" height=19px /&gt;&lt;/div&gt; &lt;div class="frame"&gt;&lt;img src="http://jsfiddle.net/img/logo.png" height=17px /&gt;&lt;/div&gt; &lt;div class="frame"&gt;&lt;img src="http://jsfiddle.net/img/logo.png" height=15px /&gt;&lt;/div&gt; &lt;div class="frame"&gt;&lt;img src="http://jsfiddle.net/img/logo.png" height=13px /&gt;&lt;/div&gt; &lt;div class="frame"&gt;&lt;img src="http://jsfiddle.net/img/logo.png" height=11px /&gt;&lt;/div&gt; &lt;div class="frame"&gt;&lt;img src="http://jsfiddle.net/img/logo.png" height=9px /&gt;&lt;/div&gt; &lt;div class="frame"&gt;&lt;img src="http://jsfiddle.net/img/logo.png" height=7px /&gt;&lt;/div&gt; &lt;div class="frame"&gt;&lt;img src="http://jsfiddle.net/img/logo.png" height=5px /&gt;&lt;/div&gt; &lt;div class="frame"&gt;&lt;img src="http://jsfiddle.net/img/logo.png" height=3px /&gt;&lt;/div&gt;</code></pre> </div> </div> </p> <hr> <p>How it works:</p> <ol> <li><p>When you have two <code>inline-block</code> elements near each other, you can align each to other's side, so with <code>vertical-align: middle</code> you'll get something like this:</p> <p><img src="https://i.stack.imgur.com/XIFPv.png" alt="Two aligned blocks"></p></li> <li><p>When you have a block with fixed height (in <code>px</code>, <code>em</code> or other absolute unit), you can set the height of inner blocks in <code>%</code>.</p></li> <li>So, adding one <code>inline-block</code> with <code>height: 100%</code> in a block with fixed height would align another <code>inline-block</code> element in it (<code>&lt;img/&gt;</code> in your case) vertically near it.</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload