中心 DIV 内容流体垂直和水平
这是我的示例:
行高不适用于流体 div。我的代码当前基于行高,但框的大小发生了变化。 那么我怎样才能让链接(内容)始终位于正中间?
我想确保此 DIV 内的内容始终从顶部和侧面均匀居中。垂直和水平居中。
当前代码:(注意样式标签为空,因为这是动态填充的)
<style type="text/css">
.box{
width:468px; /* php changes this sometimes */
height:60px; /* php changes this sometimes */
background:#eee;
text-align:
center;
border:
1px solid rgb(177, 172, 171);
line-height: 61px;
}
</style>
<div style="" class="box" id="">
<a style="color:#333;font-weight:bold" href="claimPrize();">Winner!</a>
</div>
This is the example I have:
Line height does not apply to fluid divs. The code I have is currently based on line-height but the the sizes of the boxes change. So how can I have a link (content) always in the exact middle?
I want to make sure that the content inside this DIV is always going to be equally centered from the top and the sides. Vertical and Horizontal centered.
Current code: (note style tag is blank as this is dynamic filled)
<style type="text/css">
.box{
width:468px; /* php changes this sometimes */
height:60px; /* php changes this sometimes */
background:#eee;
text-align:
center;
border:
1px solid rgb(177, 172, 171);
line-height: 61px;
}
</style>
<div style="" class="box" id="">
<a style="color:#333;font-weight:bold" href="claimPrize();">Winner!</a>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不久前遇到了类似的情况,进行了搜索,发现了一篇关于 css-tricks 绝对居中的文章, 这里是这篇文章和一个随附的小提琴来测试它。
CSS
HTML
演示
http://jsfiddle.net/andresilich/YqKMH/
Ran into a similar situation not too long ago, did a search and found an article about absolute centering from css-tricks, here is the article and an accompanying fiddle to test it out.
CSS
HTML
Demo
http://jsfiddle.net/andresilich/YqKMH/