小编han*_*nah的帖子

position:absolute bottom:0在图像上居中文本时不起作用

我正在尝试将文本放在页面上的图像中间.我想在页面上具有不同高度和宽度的其他图像上使用它.我有相对定位的图像和文本绝对定位,但底部:0似乎没有工作:

<div class="image">
<img src="http://lorempixel.com/300/300/">
    <header class="text">
        <h1>header</h1>
        <a href="#">button</a>
    </header>
</div>
Run Code Online (Sandbox Code Playgroud)

这是CSS:

.image {
  display: inline-block;
  position: relative;
}

.text {
  position: absolute;
  top: 0;
  left: 0;
  color: white;
  text-align: center;
  bottom: 0;
  right: 0;
}

.text h1 {
  text-transform: uppercase;
  font-family: Helvetica, Arial;
  font-size: 16px;
  letter-spacing: .5px;
}

.text a {
  font-size: 14px;
  border: 1px solid white;
  padding: 5px 30px;
  color: white;
  text-decoration: none;
}
Run Code Online (Sandbox Code Playgroud)

和小提琴的链接:http://jsfiddle.net/yg4Ar/

html css image absolute

4
推荐指数
2
解决办法
7750
查看次数

标签 统计

absolute ×1

css ×1

html ×1

image ×1