How to customize reCAPTCHA v2?

Asked

Viewed 2,083 times

1

I put reCAPTCHA v2 on my website, but I have a problem like:

inserir a descrição da imagem aqui

I wanted to make him responsive, so he could track the size of the fields.

I found a solution like:

transform:scale(0.77);
-webkit-transform:scale(0.77);
transform-origin:0 0;
-webkit-transform-origin:0 0;

But that only changes the scale of the element, the problem of using it this way is that it increases the width and the height and I still can’t do this responsive way.

Another solution is to use invisible reCAPTCHA v2, its problem is that it creates a "tab":

inserir a descrição da imagem aqui

In the lower right corner of the site, I have a floating button and this "tab" disturbs and I cannot hide this "tab" because of the terms and conditions of reCAPTCHA v2.

You agree explicitly to inform Visitors to your site that you have implemented the Invisible reCAPTCHA on your site and that their use of the Invisible reCAPTCHA is Subject to the Google Privacy Policy and Terms of Use.

The complicating factor here is that it is an iframe and its content does not follow the edges, ie if I put in css for example width: 100% its content does not go to the edge.

  • I went through this problem once and I found a question in the OR that said it’s not possible: Recaptcha API v2 Styling

  • I saw, but I still have hope, I had a problem with a bat, that it did not run in a folder, I went on the microsoft forum, here and everyone said that it was impossible, until after a while appeared a guy and gave me an answer that I was surprised: https://answall.com/questions/240236/como-executar-um-script-sem-me-preocupar-com-caracteres-especiais

  • I understand, I leave my +1 because this question is doubt of many people!

1 answer

2


It’s really necessary to make reCAPTCHA responsive?

In my view it is not necessary, it is not a native/standard component, to conform to other inputs, but rather an external application that often depends on a standard style.

Even in aesthetic terms, a captcha with 100% width on desktop would not be such a beautiful thing to see.

There is how to make it scale compatible with the container yes, follow an example

function scaleCaptcha(elementWidth) {
  // Width of the reCAPTCHA element, in pixels
  var reCaptchaWidth = 300;
  // Get the containing element's width
	var containerWidth = $('.container').width();
  
  // Only scale the reCAPTCHA if it won't fit
  // inside the container
  if(reCaptchaWidth > containerWidth) {
    // Calculate the scale
    var captchaScale = containerWidth / reCaptchaWidth;
    // Apply the transformation
    $('.g-recaptcha').css({
      'transform':'scale('+captchaScale+')'
    });
  }
}

$(function() { 
 
  // Initialize scaling
  scaleCaptcha();
  
  // Update scaling on window resize
  // Uses jQuery throttle plugin to limit strain on the browser
  $(window).resize( $.throttle( 100, scaleCaptcha ) );
  
});
* {
  box-sizing: border-box;
}

.container {
  max-width: 250px;
  background: #ccc;
  padding: 20px;
}

.g-recaptcha {
  transform-origin: left top;
  -webkit-transform-origin: left top;
}
<script src="https://www.google.com/recaptcha/api.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
  <p>O captcha acompanhou o container de (300 px)</p>  
  <form action="" method="get">
    <div class="g-recaptcha" data-sitekey="6LcHGhITAAAAABIgEAplK2EWsVFkaE5o0DWUpsIs"></div>
  </form>
</div>

Source Codepen

  • 1

    Very good! It worked here, needs man, the site is already all stylized, and only that tip out when it arrives in 320px resolution, and it is good to have this for future projects.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.