2017-06-13 32 views
0

我有文本和三个图像以垂直对齐基线。我已经使用垂直对齐属性通过文本底部对齐项目,但它仍然没有正确对齐。 Vertical align problem如何通过基线垂直对齐文字和图像?

请参阅透明黑匣子帮助您查看基线问题的屏幕截图。

.container { 
 
    font-size: 16px; 
 
} 
 

 
.ayc_cooperation { 
 
    margin: 0 5% 0 5%; 
 
    font-size: 0.75rem; 
 
    font-weight: 300; 
 
    color: #535353; 
 
} 
 

 
.ayc_cooperation:before { 
 
    content: ""; 
 
    display: table; 
 
    clear: both; 
 
} 
 

 
.ayc_cooperation:after { 
 
    content: ""; 
 
    display: block; 
 
    height: 6.5rem; 
 
} 
 

 
.ayc_cooperation_ini_logo { 
 
    float: left; 
 
    width: 9.6875rem; 
 
    height: 4.5rem; 
 
} 
 

 
.ayc_cooperation_ini_logo img { 
 
    width: 100%; 
 
    height: 100%; 
 
} 
 

 
.ayc_co_container { 
 
    float: right; 
 
    line-height: 8; 
 
    height: 4.5rem; 
 
} 
 

 
.ayc_co_container img { 
 
    max-width: 100%; 
 
    max-height: 100%; 
 
} 
 

 
.ayc_co_container img:first-child { 
 
    width: 7.5rem; 
 
} 
 

 
.ayc_co_container img:nth-child(2) { 
 
    width: 8rem; 
 
} 
 

 
.ayc_co_container img { 
 
    margin-right: 2.5rem; 
 
} 
 

 
.ayc_co { 
 
    display: inline-block; 
 
    margin-left: 2.5rem; 
 
    font-size: 0.75rem; 
 
    line-height: 14px; 
 
    vertical-align: text-bottom; 
 
} 
 

 
.ayc_de_lebe_ev_img { 
 
    width: 8rem; 
 
} 
 

 
.ayc_de_lebe_ev_img img { 
 
    max-width: 100%; 
 
    height: auto; 
 
} 
 

 
.ayc_de_lebe_img { 
 
    width: 7.5rem; 
 
} 
 

 
.ayc_de_lebe_img img { 
 
    max-width: 100%; 
 
    height: auto; 
 
} 
 

 
.ayc_gilead_img { 
 
    width: 6rem; 
 
} 
 

 
.ayc_gilead_img img { 
 
    max-width: 100%; 
 
    height: auto; 
 
}
<div class="container"> 
 
    <div class="ayc_co_container"> 
 
    <div class="ayc_co_text ayc_co"> 
 
     Eine Kooperation von: 
 
    </div> 
 
    <div class="ayc_de_lebe_img ayc_co"> 
 
     <img src="http://presse.bist-du-chris.de/wp-content/themes/ayc_press/assets/media/img/[email protected]" alt="Deutsche Leberstiftung"> 
 
    </div> 
 
    <div class="ayc_de_lebe_ev_img ayc_co"> 
 
     <img src="http://presse.bist-du-chris.de/wp-content/themes/ayc_press/assets/media/img/deutsche-leberhilfe[email protected]" alt="Deutsche Leberhilfe e.V"> 
 
    </div> 
 
    <div class="ayc_gilead_img ayc_co"> 
 
     <img src="http://presse.bist-du-chris.de/wp-content/themes/ayc_press/assets/media/img/[email protected]" alt="Gilead Sciences GmbH"> 
 
    </div> 
 
    </div> 
 
</div>

+0

你不能这样做,因为你的形象是一个位图图像将如何在Web浏览器知道在哪里的基准是什么? – Terry

+1

元素本身是对齐的,图像中的文本不是。 CSS不能神奇地将基于文本的元素放置在图像中。您需要编辑图像,以便文本与图像底部对齐。 –

回答

1

EDITED接听/新的代码片段:

在这个特殊的sitation的问题是,你不对齐文本,但图像,并且在底边框上面的一些空白的一些图像,这是图像的一部分,特别是在“德意志Leberstiftung”的形象。因此,实际上,您必须编辑/剪切图像才能达到所需结果,或者使用position: relativebottom设置来提升或降低它们,正如我在以下代码片段中所做的那样 - 可能仍然不完全对齐,但足以给你一个想法 - 你可以改变bottom值:

.container { 
 
    font-size: 16px; 
 
} 
 

 
.ayc_cooperation { 
 
    margin: 0 5% 0 5%; 
 
    font-size: 0.75rem; 
 
    font-weight: 300; 
 
    color: #535353; 
 
} 
 

 
.ayc_cooperation:before { 
 
    content: ""; 
 
    display: table; 
 
    clear: both; 
 
} 
 

 
.ayc_cooperation:after { 
 
    content: ""; 
 
    display: block; 
 
    height: 6.5rem; 
 
} 
 

 
.ayc_cooperation_ini_logo { 
 
    float: left; 
 
    width: 9.6875rem; 
 
    height: 4.5rem; 
 
} 
 

 
.ayc_cooperation_ini_logo img { 
 
    width: 100%; 
 
    height: 100%; 
 
} 
 

 
.ayc_co_container { 
 
    float: right; 
 
    line-height: 8; 
 
    height: 4.5rem; 
 
} 
 

 
.ayc_co_container img { 
 
    max-width: 100%; 
 
    max-height: 100%; 
 
} 
 

 
.ayc_co_container img:first-child { 
 
    width: 7.5rem; 
 
} 
 

 
.ayc_co_container img:nth-child(2) { 
 
    width: 8rem; 
 
} 
 

 
.ayc_co_container img { 
 
    margin-right: 2.5rem; 
 
} 
 

 
.ayc_co { 
 
    display: inline-block; 
 
    margin-left: 2.5rem; 
 
    font-size: 0.75rem; 
 
    line-height: 14px; 
 
    vertical-align: text-bottom; 
 
} 
 

 
.ayc_de_lebe_ev_img { 
 
    width: 8rem; 
 
\t position: relative; 
 
\t bottom: -2px; 
 
} 
 

 
.ayc_de_lebe_ev_img img { 
 
    max-width: 100%; 
 
    height: auto; 
 
} 
 

 
.ayc_de_lebe_img { 
 
    width: 7.5rem; 
 
\t position: relative; 
 
\t bottom: -4px; 
 
} 
 
} 
 

 
.ayc_de_lebe_img img { 
 
    max-width: 100%; 
 
    height: auto; 
 
} 
 

 
.ayc_gilead_img { 
 
    width: 6rem; 
 
\t position: relative; 
 
\t bottom: 0px; 
 
} 
 

 
.ayc_gilead_img img { 
 
    max-width: 100%; 
 
    height: auto; 
 
}
<div class="container"> 
 
    <div class="ayc_co_container"> 
 
    <div class="ayc_co_text ayc_co"> 
 
     Eine Kooperation von: 
 
    </div> 
 
    <div class="ayc_de_lebe_img ayc_co"> 
 
     <img src="http://presse.bist-du-chris.de/wp-content/themes/ayc_press/assets/media/img/[email protected]" alt="Deutsche Leberstiftung"> 
 
    </div> 
 
    <div class="ayc_de_lebe_ev_img ayc_co"> 
 
     <img src="http://presse.bist-du-chris.de/wp-content/themes/ayc_press/assets/media/img/[email protected]" alt="Deutsche Leberhilfe e.V"> 
 
    </div> 
 
    <div class="ayc_gilead_img ayc_co"> 
 
     <img src="http://presse.bist-du-chris.de/wp-content/themes/ayc_press/assets/media/img/gilead[email protected]" alt="Gilead Sciences GmbH"> 
 
    </div> 
 
    </div> 
 
</div>

+0

请注意我编辑的答案,其中代码片段现在包含我以前只在我的答案的文本中描述为可能性的解决方案。 – Johannes

+0

感谢您的回复。我没有编辑图像并使用display:table实现。对于移动视口,我使用display:block来替换表格实现。 – forethought