html - 如何在背景 div 气球图像中居中放置文本?

标签 html css

我在如何将带有背景图像的 div 中的文本居中时遇到困难。这是我的 fiddle

http://jsfiddle.net/VnqeY/12/

谢谢。

最佳答案

jsFiddle

只需声明line-height并设置 <a>成为vertical-align: middle

.balloon{
    background:url('http://i.imgur.com/B19Zb.jpg');
    background-repeat: no-repeat;
    text-align: center;
    color:#fff;
    font-size:1.1em;
    height:140px;
    width:140px;
    line-height: 118px;  
}
.balloon a{
    vertical-align: middle;
    color:yellow;
    text-align:center
}

<div class="balloon">
    <a href="#">Advertise with us</a>
</div>

关于html - 如何在背景 div 气球图像中居中放置文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7605485/

相关文章:

javascript - 如何像 Google 那样将默认焦点放在网页的搜索栏上

php - 如何在 virustotal api v2 for php 中获取 div 命令结构化结果?

css - 使用位置 :absolute 将 ionic 标题居中

javascript - 滚动到时自动播放youtube视频(使用youtube api)

javascript - 选择下拉菜单并单击单选按钮时显示 div

jquery - 当我调整窗口大小时如何使用滚动

performance - 在html5下动画多个 Sprite 的最快方法是什么?

html - 文本周围的 CSS 框,设置框大小

javascript - 如何从 html 文本框中获取输入并将其分配给 javascript 变量?

html - CSS 覆盖 DIV.class border-top