如何使Facebook Like Box响应?

Ric*_*ith 67 css widget responsive-design

我通过将Facebook代码粘贴到文本小部件中,在我的侧栏中使用Facebook类似的盒子代码.我的主题是响应式的,我想让类似的框正确调整大小.我找到了这个教程,但他说他这样做的方式,并不是"完全响应"所以我不知道是否有更好的方法来做到这一点.

Col*_*ton 120

注意:这个答案已经过时了.请参阅下面的社区维基解答,了解最新的解决方案.


我今天发现了这个Gist并且完美运行: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;
}
Run Code Online (Sandbox Code Playgroud)

  • 很简单的解决方案但是没有必要让浏览器呈现#fb-root元素然后将其隐藏在CSS中.只需将所有元素一起删除即可. (2认同)
  • 不要忘记在FB DIV本身中设置data-width ="100%" (2认同)

ste*_*w00 28

科林的例子让我跟按钮发生了冲突.所以我改编它只针对Like Box.

.fb-like-box, .fb-like-box span, .fb-like-box span iframe[style] { width: 100% !important; }
Run Code Online (Sandbox Code Playgroud)

在大多数现代浏览器中测试过.


ami*_*sim 26

注意:科林的解决方案对我不起作用.Facebook可能已经改变了他们的标记.使用*应该更具前瞻性.

用div包装Like框:

<div id="likebox-wrapper">
    <iframe src="..."></iframe> <!-- likebox code -->
</div>
Run Code Online (Sandbox Code Playgroud)

并将其添加到您的css文件中:

#likebox-wrapper * {
   width: 100% !important;
}
Run Code Online (Sandbox Code Playgroud)


Cla*_*lva 7

截至2015年8月4日,本地facebook like box在Facebook Developers页面上提供了响应式代码段.

您可以在此处生成响应式Facebook收件箱

https://developers.facebook.com/docs/plugins/page-plugin

这是有史以来最好的解决方案而不是黑客攻击CSS.

  • 通过勾选“适应插件容器宽度”,like 框只会在页面加载时更改宽度(而不是通过调整浏览器窗口的大小)。为了防止设计在窗口调整大小(或平板电脑方向更改)时搞砸,您还可以触发刷新或使用 width:100%; 溢出-x:隐藏;最大宽度:500px;(在周围的div上) (2认同)