html - 文本与图像垂直居中

标签 html css

我有这段代码,文本正确居中。

HTML

<div class="holder">
    <img src="http://placehold.it/100x150/" style="float: left;" />
    <a href="#" class="centered"> some text</a>
</div>

CSS

.holder {
    border: 1px solid red;
    padding: 10px;
    width: 300px;
    display: table;
}
a {
    display: table-cell;
    vertical-align: middle;
}
img {
    width: 100px;
}

http://jsfiddle.net/2P8Yj/1/

我怎样才能使文本左对齐,在图像旁边?

enter image description here

最佳答案

给你的 a 添加宽度:

a {
    display: table-cell;
    vertical-align: middle;
    width:200px;
}

DEMO HERE

关于html - 文本与图像垂直居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23653242/

相关文章:

javascript - 带有图标的 Google Chart API 行显示 Javascript 错误 : undefined is not a function

html - 从不同目录加载图像时出现问题

css - 在 div 容器底部放置一个 span

javascript - 如何在 CSS 和 HTML 中用线绘制相连的圆

html - 如何消除与位置 :relative banner 的差距

html - CSS 继承和 float :left issues

html - Jquery Mobile 仅加载 DOM 中的第一页,而不加载其他页面的 css 页面 hide() show()

javascript - 我可以使用 React 应用程序作为静态 HTML 页面上的组件吗

CSS - 哪些代码渲染速度更快、效率更高?

html - 简单的 css 悬停问题