当前位置: 动力学知识库 > 问答 > 编程问答 >

html - Center text on div when hover but inherited width and height

问题描述:

I have this code: http://jsfiddle.net/LW9DJ/1/

Now i want the overlay text to appear centered (wich is currently working) but i dont want the css class 'mycell' to have the width or height attributes setted, i want them inherited from 'container' class.

This is because i am going to implement this in a responsive website in wich the width and height of 'container' class are automatically changed.

<div class="container">

<img src="http://i.imgur.com/o7iAFMu.jpg" class="test" />

<div class="overlay">

<div class="mycell">Some Text</div>

</div>

</div>

网友答案:

You should make left-margin and right-margin properties of style, auto. When you assign auto values to these two properties, the div would be located at the center.

分享给朋友:
您可能感兴趣的文章:
随机阅读: