2013-09-05 72 views
0

如何垂直对齐图中的文字与图中的图像。如何垂直对齐图中的figcaption

参见:http://jsfiddle.net/YdATG/1/

HTML

<section class="links"> 
    <a href="#"> 
    <figure class="grid-parent clearfix"> 
      <figcaption class="grid-80 push-20 fontEmphazie">foo</figcaption> 
      <img alt="Foto" src="http://www.google.com/intl/de/homepage/images/google_favicon_64.png" class="grid-20 pull-80 grid-no-pad-left grid-no-pad-right"> 
    </figure> 
    </a> 
    <a href="#"> 
    <figure class="grid-parent clearfix"> 
       <figcaption class="grid-80 push-20 fontEmphazie">bar</figcaption> 
       <img alt="Foto" src="http://www.google.com/intl/de/homepage/images/google_favicon_64.png" class="grid-20 pull-80 grid-no-pad-left grid-no-pad-right"> 
    </figure> 
    </a> 
</section> 

CSS

section.links figure, section.links figure { 
    background-color: #f3f3f3; 
    padding: 0.5em; 
    margin-bottom: 1em; 
} 

section.links figure { 
    margin-top: 1em; 
} 

section.links figcaption, section.links figcaption { 
    padding: 0 0.5em; 
} 

section.links a, section.links a { 
    font-size: 0.9em; 
    color: #000; 
} 
+0

为什么不使用flexbox? http://stackoverflow.com/questions/15726740/vertically-centre-items-with-flexbox – quarky

+1

http://caniuse.com/flexbox? – DarsVaeda

回答

0

我想说

figure { 
    display: table; 
} 

figure a { 
    display: table-cell; 
} 

figcaption { 
    vertical-align: middle; 
} 

假设图像确定链路的大小。

+0

我错过了第一个小提琴中的ankor,对不起 – DarsVaeda

+0

好吧,这工作部分,但现在一切都没有反应了:http://jsfiddle.net/YdATG/7/ ...啊我没有得到这个表的东西:/ – DarsVaeda

+0

垂直对齐意味着在表格中使用(也可能在其他一些事情中),这就是您必须将父元素作为表格和表格单元格的内容。 – Virus721