Responsive Facebook Comments CSS Hack Broken

后端 未结 17 1699
渐次进展
渐次进展 2020-12-12 22:48

I was using:

.fb-comments, .fb-comments span, .fb-comments iframe[style] {
    width: 100% !important;
}

To make Facebook Comments responsi

相关标签:
17条回答
  • 2020-12-12 23:25

    I tried data-width="100%" and worked for me, but when I resize the screen the container remains the same size, it doesn't change, I tried with Ripple plugin for chrome and it looks good but I have to tap or click twice to comment.

    0 讨论(0)
  • 2020-12-12 23:28

    This is the only solution that has worked for me. (You need the FB root bit too) Original found here: http://jsfiddle.net/PZD54/4/

            <script>
            setTimeout(function(){
              resizeFacebookComments();
            }, 1000);
            $(window).on('resize', function(){
              resizeFacebookComments();
            });
            function resizeFacebookComments(){
              var src   = $('.fb-comments iframe').attr('src').split('width='),
              width = $('#comments').width();
              $('.fb-comments iframe').attr('src', src[0] + 'width=' + width);
            }
          </script>
          <div id="comments">
            <div class="fb-comments" data-href="http://www.url-here.com"></div>
          </div>
    
    0 讨论(0)
  • 2020-12-12 23:30

    I got bit by this too. I put in a JS hack. Basically bind to the resize event of the window and redraw the comments widget when it fires (uses jquery if you want I can post without):

    $(window).resize(function(){
     $(".fb-comments").attr("data-width", $(".comments").width());
     FB.XFBML.parse($(".comments")[0]);
    });
    

    In the example above .comments is the container that you want the width of the fb-comments to expand to. The downside of this is that when the window is resized the comments widget is reinitialized.

    If you use underscore wrap the resize handler using debounce to keep it from firing to often.

    0 讨论(0)
  • 2020-12-12 23:31

    Here's a new CSS-only solution. Did this for a project I'm working on today (July 16, 2014) and it works beautifully.

    HTML

    <div class="fb-comments"
         data-href="http://example.com/comments"
         data-numposts="10"
         data-width="100%"
         data-colorscheme="light"></div>
    

    CSS

    .fb_iframe_widget,
    .fb_iframe_widget span,
    .fb_iframe_widget span iframe[style] {
      min-width: 100% !important;
      width: 100% !important;
    }
    

    The trick are data-width: 100% and min-width: 100% !important; width: 100% !important;

    0 讨论(0)
  • 2020-12-12 23:31

    I had the same issue (implemented the responsive comments yesterday, today it didn't work anymore ).

    I don't have enough points to vote but the above answer works. I am using the facebook plugin for wordpress. I also set a timeout when the page loads to get the right width immediately.

    setTimeout(function(){
        $(".fb-comments").attr("data-width", $(".comments-area").width());
         FB.XFBML.parse($(".comments-area")[0]);
    }, 1000)
    
    0 讨论(0)
  • 2020-12-12 23:32

    An adaptive pure CSS approach can be found here:

    http://jsfiddle.net/bennyaarup/5gyp6/

    HTML

    I add FB comment code blocks in duplicate - amounting to the number of adaptive stages (data-width) I need. I add the extra class = .fb-1, .fb-2, .fb-3 etc... which I need in the CSS.

    <div class="fb-comments fb-1" data-href="http://yourdomain.com" data-width="900" data-numposts="5" data-colorscheme="light"></div>
    
    <div class="fb-comments fb-2" data-href="http://yourdomain.com" data-width="800" data-numposts="5" data-colorscheme="light"></div>
    
    <div class="fb-comments fb-3" data-href="http://yourdomain.com" data-width="700" data-numposts="5" data-colorscheme="light"></div>
    
    <div class="fb-comments fb-4" data-href="http://yourdomain.com" data-width="600" data-numposts="5" data-colorscheme="light"></div>
    
    <div class="fb-comments fb-5" data-href="http://yourdomain.com" data-width="500" data-numposts="5" data-colorscheme="light"></div>
    
    <div class="fb-comments fb-6" data-href="http://yourdomain.com" data-width="400" data-numposts="5" data-colorscheme="light"></div>
    
    <div class="fb-comments fb-7" data-href="http://yourdomain.com" data-width="300" data-numposts="5" data-colorscheme="light"></div>
    
    <div class="fb-comments fb-8" data-href="http://yourdomain.com" data-width="200" data-numposts="5" data-colorscheme="light"></div>
    

    CSS

    I style the adaptive stages using media queries and display:none to show the respective comment field

    @media all and (min-width: 400px), (max-width: 300px) {
    
    .fb-8{
    display: none !important;
    }
    }
    
    @media all and (min-width: 500px), (max-width: 400px) {
    
    .fb-7{
    display: none !important;
    }
    }
    
    
    @media all and (min-width: 600px), (max-width: 500px) {
    
    .fb-6 {
    display: none !important;
    }
    }
    
    
    @media all and (min-width: 700px), (max-width: 600px) {
    
    .fb-5 {
    display: none !important;
    }
    }
    
    @media all and (min-width: 800px), (max-width: 700px) {
    
    .fb-4 {
    display: none !important;
    }
    }
    
    
    @media all and (min-width: 900px), (max-width: 800px){
    
    .fb-3 {
    display: none !important;
    }
    }
    
    
    @media all and (min-width: 1000px), (max-width: 900px){
    
    .fb-2 {
    display: none !important;
    }
    }
    
    
    @media all and (max-width: 1000px) {
    
    .fb-1 {
    display: none !important;
    }
    }
    

    It's a bit of a hack, but it works beautifully

    0 讨论(0)
提交回复
热议问题