这是我的摘要代码
HTML:
<div class="wrap">
<div>
<img src="Pictures/titlepic.jpg" width="1035" height="200">
<h1 class="text_over_image">Welcome to my Sandbox</h1>
</div>
</div>
CSS:
.wrap{
width: 1060px;
margin: auto;
}
.text_over_image{
position: absolute;
top: 20px;
}
我已经尝试过left: 50%
,,text-align:center
许多事情,没有好运。我不想做一个left: 50px
(或任何需要的值),因为看不见的是文本的长度根据Javascript值而变化。因此标题可能是短的,也可能是长的,无论如何我都希望它居中。
有想法吗?
尝试以下CSS:
.text_over_image{
position: absolute;
top: 0;
left:0;
right:0;
bottom:0;
}
===编辑===
.wrap {
width: 1060px;
height:auto;
margin: auto;
text-align:center;
position:relative;
}
.text_over_image {
position: absolute;
margin: auto;
top: 0;
left:0;
right:0;
bottom:0;
color:#fff;
height:100px;
}
你去JsFiddle
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句