css - 如何在 div 标签中居中视频标签?

标签 css

我似乎无法使用通常的“margin: 0px auto 0px auto;”来定位这个视频标签。
帮助小伙子们!感谢您查看这个!

#wrapper #trailer {
    position: absolute;
    z-index: 3;
    margin-top: 55px;
    width: 987px;
    height: 620px;
    background-color: #000;
    margin-right: auto;
    margin-bottom: 0px;
    margin-left: auto;
    border: 1px solid #009;
}
#wrapper #trailer #close {
    position: absolute;
    z-index: 2;
    top: 20px;
    right: 231px;
    cursor: pointer;
}
#wrapper #trailer video {
        margin-top: 0px;
    margin-right: auto;
    margin-bottom: 0px;
    margin-left: auto;
    border: 1px solid #009;
}

和 html 并根据要求解释我的场景:
<div id="trailer">
<img id="close" src="images/close.png" alt="close" />
<div id="video">
<video controls  autoplay="autoplay" poster="video/trailer.jpg" width="600"      onclick="if(/Android/.test(navigator.userAgent))this.play();">
<source src="video/trailer.mp4" type="video/mp4" />
<source src="video/trailer.webm" type="video/webm" />
<source src="video/trailer.ogv" type="video/ogg" />
<embed src="video/flashfox.swf" width="600" height="480"  flashVars="autoplay=true&amp;controls=true&amp;loop=true&amp;src=trailer.mp4" allowFullScreen="true" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer_en" />
</video>
</div>
</div>

最佳答案

实际上,对于样式表,html5 视频和图像都算作文本。因此,您必须进行的唯一更改是在您的 css 代码中。使用 <div id="video>用标签包裹视频,您只需要添加:

#video {
   text-align: center;
   //rest of rules here
}

而不是整天玩 margin 。

关于css - 如何在 div 标签中居中视频标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13033925/

相关文章:

html - 如何在 Angular 6 中单击图像更改边框半径

jQuery 滚动条间距问题

css - 图像适合框架 (Woocommerce)

python - Django 缓存 CSS(?)

javascript - 为什么这个半圆不长大?

javascript - 由于 css 树,无法添加或删除类。 JQuery 中的所有内容{单击并悬停)

html - 翻转图像,然后在 html 中引用该图像

jQuery - 根据最后一个字符更改下拉选择的颜色

jquery - 影响所有宽度最小宽度的图像

CSS 样式冲突