Centering No Captcha reCaptcha
After a few hours of research and trial and error, I was finally able to add the new Google No Capatcha re Capatcha to my form and get it working, but for some reason, it won't center. Any ideas?
<!-- reCapatcha -->
<div id="capatcha">
<div class="g-recaptcha" data-sitekey=""></div>
</div>
#capatcha {
margin: 0 auto;
display: block
}
Solution 1:
I went with:
<style>
/* already defined in bootstrap4 */
.text-xs-center {
text-align: center;
}
.g-recaptcha {
display: inline-block;
}
</style>
<div class="text-xs-center">
<div class="g-recaptcha" data-sitekey=""></div>
</div>
Solution 2:
This is similar to other answers, but I thought worth sharing. I don't like hard-coding values, but the width of the No Captcha reCAPTCHA appears to be 304px, so you could use that as your width:
<style>
div.g-recaptcha {
margin: 0 auto;
width: 304px;
}
</style>
<!-- reCAPTCHA -->
<div class="g-recaptcha" data-sitekey=""></div>
This should center the reCAPTCHA exactly.
Solution 3:
This css works fine for me:
.g-recaptcha{
margin: 15px auto !important;
width: auto !important;
height: auto !important;
text-align: -webkit-center;
text-align: -moz-center;
text-align: -o-center;
text-align: -ms-center;
}
Solution 4:
I don't like the idea of hardcoding 304px
in my .scss
The g-recaptcha html is generated as:
<div class="g-recaptcha" ... >
<div style="width: 304px; height: 78px;">
<div>
<iframe ... ></iframe>
</div>
<textarea ... ></textarea>
</div>
</div>
This horizontally centres the first inner div (which specifies width=304px).
<style>
.g-recaptcha > div {
margin: 0 auto;
}
</style>