点赞按钮的 CSS 中心

发布于 2024-12-09 11:45:33 字数 1598 浏览 0 评论 0原文

我已经完成了研究,但没有找到关于我的问题的任何好的信息。如果您访问 www.metrochristianguide.com,您会看到我在页面顶部放置了一个“喜欢”按钮,并将

背景颜色设置为红色。我这样做是为了查看类似按钮和文本的水平对齐方式。

这是我的代码...

<table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr><td id='relative' width='100%' height="98">
        <img src='images/2011_gold_banner.jpg' border='0' width='100%' height='98'>
        <div style='position: absolute; top: 25px; left: 50px;'>
            <a href='http://www.metrochristianguide.com'><img src='images/new_2011_logo_trans.gif' border='0'></a>
        </div>
        <center><div id="fb-root"></div>
        <script>
        (function(d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) {return;}
            js = d.createElement(s); js.id = id;
            js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
            fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));
        </script>
        <div style='text-align: center; background-color: red; float: center; top: -58px;' class="fb-like" data-href="http://www.facebook.com/pages/Metro-Christian-Guide/214303935583" data-send="false" data-width="500" data-show-faces="false" data-font="arial" data-action="recommend"></div>

我尝试了该网站上的建议之一,将

标签放置在

周围。 ..那不起作用。我也尝试过使用 CSS 样式,“text-align: center;”...但这也不起作用。

有人还有其他建议吗?

I have done my research and haven't found any good information on my problem. If you go to www.metrochristianguide.com, you will see that I placed a "Like" button on the top of the page, and set the <DIV> background color to red. I did this to see the horizontal alignment of the like button and text.

Here is my code...

<table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr><td id='relative' width='100%' height="98">
        <img src='images/2011_gold_banner.jpg' border='0' width='100%' height='98'>
        <div style='position: absolute; top: 25px; left: 50px;'>
            <a href='http://www.metrochristianguide.com'><img src='images/new_2011_logo_trans.gif' border='0'></a>
        </div>
        <center><div id="fb-root"></div>
        <script>
        (function(d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) {return;}
            js = d.createElement(s); js.id = id;
            js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
            fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));
        </script>
        <div style='text-align: center; background-color: red; float: center; top: -58px;' class="fb-like" data-href="http://www.facebook.com/pages/Metro-Christian-Guide/214303935583" data-send="false" data-width="500" data-show-faces="false" data-font="arial" data-action="recommend"></div>

I tried one of the suggestions on this site to just place <CENTER></CENTER> tags around the <DIV>... that didn't work. I have also tried using CSS style, "text-align: center;"... that also didn't work.

Does anyone have any other suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

紫竹語嫣☆ 2024-12-16 11:45:33
.fb-like {text-align: center;}
.fb_iframe_widget {display: block !important;}

希望这有帮助...

.fb-like {text-align: center;}
.fb_iframe_widget {display: block !important;}

Hope this helps...

青萝楚歌 2024-12-16 11:45:33

好消息是您的 div 居中,但“赞”按钮 iframe 的宽度为 500 像素。这就是您看到的额外的红色空间。您可以在like按钮代码中调整iframe的宽度:

<div style='text-align: center; background-color: red; float: center; top: -58px;' class="fb-like" data-href="http://www.facebook.com/pages/Metro-Christian-Guide/214303935583" data-send="false" data-width="500" data-show-faces="false" data-font="arial" data-action="recommend"></div>

data-width属性控制iframe的宽度。您可以调整它以满足您的需求,但它需要明确的宽度,Facebook 为按钮动态生成的 iframe 无法折叠到其中的内容。

data-width=400 非常接近我在 Chrome 上的正确宽度。但内容会根据观看者、他们的朋友是否“喜欢”等而改变。

The good news is that your div is centering, but your Like button iframe is 500 pixels wide. That's the extra red space you're seeing. You can adjust the width of the iframe in the like button code:

<div style='text-align: center; background-color: red; float: center; top: -58px;' class="fb-like" data-href="http://www.facebook.com/pages/Metro-Christian-Guide/214303935583" data-send="false" data-width="500" data-show-faces="false" data-font="arial" data-action="recommend"></div>

The data-width attribute controls the width of the iframe. You can adjust it to suit your needs, but it will need an explicit width, the iframe that Facebook dynamically generates for the button can't collapse to the content within.

A data-width=400 is pretty close to the right width for me on Chrome. But the contents will change depending on who's viewing, whether any of their friends have "liked" it, etc.

无法言说的痛 2024-12-16 11:45:33

你的想法是正确的。问题在于“Like 按钮”的内容是在 IFRAME 内部呈现的。所以你的 CSS 不会在 IFRAME 中被获取。

You had the right idea. The problem is that the contents of the "Like button" are rendered inside of an IFRAME. So your CSS doesn't get picked up inside the IFRAME.

空名 2024-12-16 11:45:33

许多年后...

https://developers.facebook 提供的示例代码。 com/docs/plugins/like-button#

<iframe src="https://www.facebook.com/plugins/like.php?href=<your URL>&width=320&layout=button&action=like&size=large&share=true&height=65&appId=XXX" width="320" height="65"...></iframe>

将 width=320 的两个实例更改为 width=150。也就是说:

<iframe src="https://www.facebook.com/plugins/like.php?href=<your URL>&width=150&layout=button&action=like&size=large&share=true&height=65&appId=XXX" width="150" height="65"...></iframe>

尚未广泛测试此解决方案,但似乎适用于各种屏幕尺寸的 Chrome 桌面/移动设备。也没有尝试过将它用于 JS SDK。另请注意,它是针对“按钮”布局的,并且它是一个彻底的黑客而不是正确的解决方案。 ;-) 请随意将 150 更改为更适合您的目的的值。

Many years later...

Sample code as provided from https://developers.facebook.com/docs/plugins/like-button# :

<iframe src="https://www.facebook.com/plugins/like.php?href=<your URL>&width=320&layout=button&action=like&size=large&share=true&height=65&appId=XXX" width="320" height="65"...></iframe>

Change the two instances of width=320 to width=150. That is:

<iframe src="https://www.facebook.com/plugins/like.php?href=<your URL>&width=150&layout=button&action=like&size=large&share=true&height=65&appId=XXX" width="150" height="65"...></iframe>

Haven't tested this solution extensively, but seems to work for Chrome desktop/mobile at various screen sizes. Haven't tried using it for JS SDK either. As well, note that it's for the "button" layout and that it's a total hack instead of a proper solution. ;-) Feel free to change the 150 to something more suitable for your purposes.

夜灵血窟げ 2024-12-16 11:45:33

如果您使用引导程序,可以按照以下方式完成,它不会居中对称,但这对我来说已经足够了。

<div class="row">
<div class="col-md-2 col-md-offset-5">
here put all facebook like code
</div>
</div>

If you are using bootstrap it can be done the following way, it will not be centered symmetric but it was enough for me.

<div class="row">
<div class="col-md-2 col-md-offset-5">
here put all facebook like code
</div>
</div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文