2

My DIV of showing the Facebook comments plugin (e.g. .fb-comments) is fixed by CSS, consider that if I cannot modify that CSS, is it possible to resize the comments plugin using pure JS solution after all comments are loaded?

 <div style='background-color:red;height:200px;' 
       class="fb-comments" data-href="http://example.com" 
       data-num-posts="10"></div>

Demo: http://jsfiddle.net/8MyV3/1/

Ryan
  • 10,041
  • 27
  • 91
  • 156

3 Answers3

2

It is very much possible.

The .fb-comments class is set via CSS, but you can still use the !important flag to overwrite it.

Lets get to it:

  1. First you need to overwrite some CSS:

    .fb-comments, .fb-comments * {
        width:100% !important;
    }
    
  2. Then you can place your facebook comments widget in its own container

    <div class="fb_container">
            <div class="fb-comments" data-href="http://example.com" data-num-posts="10"></div>
    </div>
    
  3. Optional - Style it with CSS however you want:

    .fb_container{
       width: 200px;
    }
    
  4. And then you can change it programatically with JS:

     $(".fb_container").css("width","200px");
    

Here's a working jsFiddle example

OpherV
  • 6,787
  • 6
  • 36
  • 55
1

This code should do the trick:

$('.fb-comments').attr('data-width', '200');

That will make ".fb-comments" 200px wide.

0

Need to update three elements to make fully resized.

$('.fb-comments').attr('data-width', '200');
$('.fb-comments span').css('width', '200');
$('.fb-comments span iframe').css('width', '200');
user2326737
  • 211
  • 1
  • 4
  • 16