我有以下代碼中心文字立式元素改變高度和寬度
http://codepen.io/anon/pen/EZeVXG
HTML
<a href="#" class="col-inner">
<img src="http://placehold.it/450x450" />
<div class="content">
<h3>Hello World</h3>
<p>Lorem Ipsum Dolor Sit Amet</p>
</div>
</a>
CSS
img{
max-width: 100%;
height: auto;
}
.col-inner{
position: relative;
display: inline-block;
}
.content{
position: absolute;
width: 90%;
height: 90%;
top: 5%;
left: 5%;
background-color: rgba(0,0,0,.7);
color: #FFF;
text-align: center;
}
我已經嘗試了一堆堆棧溢出技術,但一切似乎只有當你知道寬度和heig工作H T。這兩個屬性將隨着您瀏覽器的彈性而改變。有什麼方法可以讓文本垂直居中?
可能重複的[如何將元素水平和垂直居中?](http://stackoverflow.com/questions/19461521/how-to-center-an-element-horizontally-and-vertically) – chazsolo