ReCaptcha API v2 Styling

前端 未结 18 1857
孤城傲影
孤城傲影 2020-11-28 02:59

I have not had much success finding how to style Google\'s new recaptcha (v2). The eventual goal is to make it responsive, but I am having difficulty applying styling for ev

18条回答
  •  生来不讨喜
    2020-11-28 03:47

    Just adding a hack-ish solution to make it responsive.

    Wrap the recaptcha in an extra div:

    Add styles. This assumes the dark theme.

    // Recaptcha
    .recaptcha-wrap {
        position: relative;
        height: 76px;
        padding:1px 0 0 1px;
        background:#222;
        > div {
            position: absolute;
            bottom: 2px;
            right:2px;
            font-size:10px;
            color:#ccc;
        }
    }
    
    // Hides top border
    .recaptcha-wrap:after {
        content:'';
        display: block;
        background-color: #222;
        height: 2px;
        width: 100%;
        top: -1px;
        left: 0px;
        position: absolute;
    }
    
    // Hides left border
    .recaptcha-wrap:before {
        content:'';
        display: block;
        background-color: #222;
        height: 100%;
        width: 2px;
        top: 0;
        left: -1px;
        position: absolute;
        z-index: 1;
    }
    
    // Makes it responsive & hides cut-off elements
    #g-recaptcha {
        overflow: hidden;
        height: 76px;
        border-right: 60px solid #222222;
        border-top: 1px solid #222222;
        border-bottom: 1px solid #222;
        position: relative;
        box-sizing: border-box;
        max-width: 294px;
    }
    

    This yields the following:

    It will now resize horizontally, and doesn't have a border. The recaptcha logo would get cut off on the right, so I am hiding it with a border-right. It's also hiding the privacy and terms links, so you may want to add those back in.

    I attempted to set a height on the wrapper element, and then vertically center the recaptcha to reduce the height. Unfortunately, any combo of overflow:hidden and a smaller height seems to kill the iframe.

提交回复
热议问题