注意: 该回答已经过时。请参考下面的社区维基回答,以获得最新的解决方案。
我今天发现了这个代码片段,它完美地工作:https://gist.github.com/2571173
(感谢https://gist.github.com/smeranda)
/*
Make the Facebook Like box responsive (fluid width)
https://developers.facebook.com/docs/reference/plugins/like-box/
*/
/*
This element holds injected scripts inside iframes that in
some cases may stretch layouts. So, we're just hiding it.
*/
#fb-root {
display: none;
}
/* To fill the container and nothing else */
.fb_iframe_widget, .fb_iframe_widget span, .fb_iframe_widget span iframe[style] {
width: 100% !important;
}
Colin给我的示例与“喜欢”按钮冲突。因此,我将其改为仅针对“赞”框。
.fb-like-box, .fb-like-box span, .fb-like-box span iframe[style] { width: 100% !important; }
已在大多数现代浏览器中进行了测试。
max-height
值的媒体查询结合使用效果很好。 - nickbiframe[style]
只是针对任何设置了 style
属性的 iframe
元素。也就是说,它会忽略 <iframe src="..."></iframe>
,但会成功地定位到 <iframe src="..." style=""></iframe>
。 - nickb注意:Colin的解决方案对我无效。Facebook可能已经更改了它们的标记。使用*
应该更具有未来性。
将Like框包装在一个div中:
<div id="likebox-wrapper">
<iframe src="..."></iframe> <!-- likebox code -->
</div>
#likebox-wrapper * {
width: 100% !important;
}
width="xxxpx"
, 这破坏了该方法。 - stephen.hanson对我来说,所有的CSS技巧都没有起作用(在我的情况下,fb-like框被右浮动)。然而,没有任何额外的技巧可以解决问题的是按钮代码的IFRAME版本。也就是:
<iframe src="//www.facebook.com/plugins/like.php?href=..."
scrolling="no" frameborder="0"
style="border:none; overflow:hidden; width:71px; height:21px;"
allowTransparency="true">
</iframe>
(请注意样式中的自定义宽度,无需包含其他JavaScript。)
我试图使用“ fb_likebox”模块(https://drupal.org/project/fb_likebox)在Drupal 7上实现响应式。结果我不得不编写自己的Contrib模块Variation并删除宽度设置选项(默认高度选项对我没有影响)。一旦我删除了宽度,我就在fb_likebox.tpl.php中添加了<div id="likebox-wrapper">
。
这是我的CSS样式:
`#likebox-wrapper * {
width: 100% !important;
background: url('../images/block.png') repeat 0 0;
color: #fbfbfb;
-webkit-border-radius: 7px;
-moz-border-radius: 7px;
-o-border-radius: 7px;
border-radius: 7px;
border: 1px solid #DDD;}`