如何使 Facebook 评论小部件具有流体宽度?
是否可以使 Facebook 的评论小部件具有流动宽度?他们的文档显示了fb:comments
xfbml或iframe的宽度字段指定为:
- width - 插件的宽度(以像素为单位)。建议的最小宽度:400px。
所以也许这是不可能的...
Is it possible to make Facebook's comments widget a fluid width? Their documentation shows a width field for the fb:comments
xfbml or iframe which is specified as:
- width - the width of the plugin in pixels. Minimum recommended width: 400px.
So maybe it's not possible...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(19)
艾伦,你的解决方案正在工作,但看起来 Facebook 更新了他们的插件并打破了风格。我使用通用选择器让它再次工作:
Alan your solution was working however it looks like facebook updated their plugin and broke the style. I got it working again using the universal selector:
我找到了一个使用CSS的解决方案。灵感来自于这篇文章
http://css-tricks.com/2708-override-inline-样式与 css/
I found a solution using css. Inspiration came from this article
http://css-tricks.com/2708-override-inline-styles-with-css/
可能是 FB 的下一次更改,这次效果更好:
Probably next change from FB and this time this works better:
截至 2014 年 3 月,没有一个 CSS 解决方案对我有用。Facebook 似乎已更改插件,现在在 iFrame 内的容器上设置宽度,您无法使用 CSS 覆盖该宽度。
经过一番挖掘,我注意到注释的宽度实际上是由 iframe src
width=XXX
的最后一个参数控制的。考虑到这一点,我是这样解决的:#container
是您希望评论插件拉伸以适应的容器的宽度。将其更改为您需要的任何内容,并且此代码应该适合您。我使用了超时,因为加载 iframe 后我无法让它触发。对此的任何帮助将不胜感激,但超时可以完成这项工作。
编辑:此解决方案会导致后退按钮损坏。我现在正在尝试这个解决方案,它似乎更好: https://stackoverflow.com/a/22257586/394788
None of the CSS solutions worked for me as of March 2014. It seems that Facebook has changed the plugin to now set a width on a container within the iFrame which you are unable to override with CSS.
After a little digging, I noticed that the width of the comments are actually controlled by the last param of the iframe src
width=XXX
. With that in mind, here's how I solved it:#container
is the width of your container that you want the comments plugin to stretch to fit within. Change this to whatever you need it to be and this code should work for you.I'm using a timeout because I wasn't able to get it to fire once the iframe was loaded. Any help on that would be appreciated but the timeout does the job.
EDIT: This solution causes the back button to break. I'm trying out this solution now and it seems to be better: https://stackoverflow.com/a/22257586/394788
我想我有一个解决方案,可以对 Ryan 3 月 5 日的回答进行一些改进。
您可以执行以下操作,而不是在延迟后重新加载 Facebook iframe。
插入一个常规的 Facebook 评论标签,但在类中附加一个额外的位,这样 Facebook 就不会检测到它,但您可以。
然后添加一些 JS 来选取这个 div,将其修改为所需的宽度,然后触发 Facebook 的解析器。
I think I have a solution which improves a little on Ryan's answer from March 5th.
Rather than re-loading the Facebook iframe after a delay, you could do the following.
Insert a regular Facebook comments tag, but append an extra bit to the class, so that Facebook doesn't detect it, but you can.
Then add some JS which picks this div up, modifies it with the desired width, then triggers Facebook's parser.
Facebook 已经解决了这个问题。您现在可以添加
data-width="100%"
或将宽度选项设置为100%
并根据需要删除任何疯狂的 js hack!This problem has been addressed by Facebook. You can now add
data-width="100%"
or set the width option to100%
and delete any crazy js hacks as appropriate!我通常希望避免使用通用选择器以获得更好的性能。 如果您检查 facebook 选择器,您应该能够得到相同的结果,
可能会得到更多改进...
I generally want to avoid using the universal selector for better performance. You should be able to get the same result with
Could probably be improved upon more if you check the facebook selectors...
在初始化 Facebook 插件之前插入此代码,您将获得流畅的 Facebook 评论:):):)
insert this code before initialize facebook plugin and you will have fluid fb comments :):):)
看起来 facebook 更新了他们的文档..你现在可以使用 data-width="100%" 或 width="100%"
https://developers.facebook.com/docs/plugins/comments/
looks like facebook updated their documentation..you can now use data-width="100%" or width="100%"
https://developers.facebook.com/docs/plugins/comments/
我还不能发表评论,因为我的声誉还不够高,但是截至 2014 年 12 月 21 日,有一个解决方案
可以在 CSS 中工作:
您必须将 data-width="" 部分设置为 100% FB 插件代码即
流体运动的工作示例:http://www.unitedbiker.org
希望这对大家有所帮助,其想法是将 iframe 样式覆盖为 100% 的父元素,并设置实际的FB插件到100%的iframe。这就是我的工作。
I can't comment yet because my reputations not yet high enough, however there is a solution to this as of Dec 21, 2014
for this to work in CSS:
you MUST have the data-width="" section set to 100% within the FB plugin code i.e
working example with fluid motion: http:www.unitedbiker.org
Hope this helps everyone out, the idea is to override the iframe style to be 100% of the parent element, and to set the actual FB plugin to 100% of the iframe. This was my work around.
这对我有用,但我需要添加 span 标签才能正常工作:
This worked for me, but I need to add span tag to work correctly:
我认为这对每个人都有效。 2013 年 12 月 26 日在 http://eddie11.com/dj-eddie-talks/
以下内容都不适合我,但我还是把它留在那里。
I think this will work for everyone. Works for me Dec 26, 2013 at http://eddie11.com/dj-eddie-talks/
None of the below worked for me but I left it there anyway.
我知道这是一个老问题,但这也许对某人有帮助。
你可以使用下面的代码让你的注释变得流畅
可以检查这里的代码,因为这里的pre函数删除了一些东西。我是新来的。问候
Facebook 评论流畅
I know this is old question, but this maybe can help to someone.
You can use the following code to make your comments fluid
Can check the code here, because the pre function here delete some things. I'm new here. Regards
Facebook Comments Fluid
花了一些时间调查这个问题。尽管 FB 建议以像素为单位指定绝对宽度,但看起来只要将其设置为“100%”就可以了。请注意下面的数据宽度。
是的,这很简单,没有 onresize 回调,没有 iframe src 修改。
spent some time investigating this issue. Though FB proposes to specify absolute width in pixels, looks like it works if you just set it to '100%'. Note data-width below.
Yeah yeah, that's easy, no onresize callbacks no iframe src modifications.
在解决这个问题相当长一段时间后,我发现了一个花絮,它应该可以帮助您弄清楚此页面上的哪些 CSS 技巧将有助于您的 Facebook 评论插件的特定站点/版本/年份。在浏览器中查看您的网站并检查 Facebook 评论插件周围的元素。你应该找到你添加的一个片段,现在由 facebook 的 javascript 小部件修饰,看起来像这样:
记下这样的部分:
这是你想要使用的类 - 所以在我上面的示例中,你需要添加以下款式:
After grappling with this for quite some time I found a tidbit that should help you to figure out which of the CSS tricks on this page will help for your particular site/version/year of facebook's comment plugin. Look at your site in a browser and inspect the elements around the facebook comment plugin. You should find a snippet that you added and is now embellished by facebook's javascript widget that looks something like this:
take note of the part that says:
this is the class you want to use - so in my example above, you would want to add the following styles:
如果您的 Facebook 评论插件的代码类似于 (XFBML):
那么以下 CSS 应该可以完成工作:
If your Facebook Comments Plugin's code looks like (XFBML):
Then the following CSS should get the job done:
这是唯一对我来说正确的事情!
This is the only thing that worked correctly for me!
无需覆盖CSS,使用
data-width="100%"
No need to override the css, Use
data-width="100%"