视频中心 html5,以html5中的视频为中心的文本

好吧,z-index: -1将在Firefox搞砸。使用这个:

// all the video stuff goes in here.

#video-container {

text-align: center;

height: 400px;//or whatever you want

line-height:400px;//should be equal to the height

position: ..

z-index: 1;

}

#custom-message {

position: relative;

display: inline-block;

height:..;

width:..;

z-index: 10;

}

尽管如此,最好的方法是使用JavaScript。无论如何,您都需要使用z-index,因此相对定位视频容器(绝对自定义消息),但在视频容器内部,然后使用JavaScript来计算自定义消息的left和top。波纹管是原始的JavaScript(无库)方式。

window.onload = funciton() {

var video = document.getElementById('video-container');

var customMessage = document.getElementById('custom-message');

var customMessageTop = video.offsetHeight/2 - customMessage.offsetHeight/2;

var customMessageLeft = video.offsetWidth/2 - customMessage.offsetWidth/2;

customMessage.style.left = customMessageLeft + 'px';

customMessage.style.top = customMessageTop + 'px';

};

或者如果你已经在使用jQuery作为你的东西了。

$(function() {

$('#customMessage').css({

top: $('#video').height()/2 - $('#customMessage').height()/2,

left: $('#video').width()/2 - $('#customMessage').width()/2

});

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值