【发布时间】:2013-07-08 12:59:20
【问题描述】:
我希望将没有固定宽度的 div 居中放置在视频上,因此如果调整窗口大小,该 div 将随之缩小,但仍保持在中心。我目前的设置接近于使用 left:50% 和一半负边距的正确设置。问题显然是它向左移动,因为负边距是固定的。有任何想法吗?谢谢!
我的 HTML:
<div id = 'top-container'>
<video id='top-vid' autoplay loop width=100% height='auto' class='no-mobile'>
<source src='DS_Intro.mov' type='video/mp4'>
<source src='test.webm' type='video/webm'>
</video>
<div id = 'top-content'>
<div id = 'top-text'>
<div id = 'top-img'>
<img src='ds_white.png' width = "100%" height = 'auto'>
</div>
<h1 id = 'top-slogan'>a boutique video production studio</h1>
</div>
</div>
</div>
我的 CSS:
#top-container{
width:100%;
height:100%;
}
#top-content{
max-width:1200px;
margin-right:auto;
margin-left:auto;
}
#top-img{
width:100%;
padding-bottom: 10%;
}
#top-slogan{
text-align:center;
padding-bottom:10%;
font-weight: 100;
color:#5DBCD2;
}
#top-text {
top: 50%;
left: 50%;
margin-left: -360px;
position:absolute;
width:50%;
}
这里是FIDDLE
【问题讨论】:
-
在
#top-text规则中尝试margin: 50% auto 0;。