the*_*he_ 3 html javascript css twitter iframe
我正在使用 Twitter oembed api,现在我的页面上有以下代码:
<div class='row'>
<iframe id="twitter-widget-0" scrolling="no" frameborder="0" allowtransparency="true" class="twitter-tweet twitter-tweet-rendered" style="display: block; max-width: 99%; min-width: 220px; padding: 0px; border-top-left-radius: 5px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; margin: 10px 0px; border-color: rgb(238, 238, 238) rgb(221, 221, 221) rgb(187, 187, 187); border-width: 1px; border-style: solid; box-shadow: rgba(0, 0, 0, 0.14902) 0px 1px 3px; position: static; visibility: visible; width: 500px;" title="Embedded Tweet" height="186"></iframe>
<script async="" src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
</div>
Run Code Online (Sandbox Code Playgroud)
基本上我想做的就是将 iframe 在 .row 中水平居中,但只能使用 CSS,因为我不控制与 iframe 内联的任何样式。margin:0 auto;似乎不起作用。
我假设您无法更改此 iFrame 的内联样式来回答我的问题。
问题是你的内联样式覆盖了你的margin: 0 auto;类。解决这个问题的方法是像这样扔到!important你的班级上。margin: 0 auto;
.row iframe{
margin:0 auto !important;
display:block;
}
Run Code Online (Sandbox Code Playgroud)
如果您可以编辑 iFrame 的内联样式,那么您可以删除margin:10px 0px;或编辑您想要的结果margin: 10px auto;