Search code examples
htmlcssborderfont-awesomebox-shadow

Inverted elliptical border on button with icon


I have the following button with the missing border on the left side:

Add to cart button

How can I add the missing border on the left side of the button?

This is a button with an font-awesome icon and a box-shadow. (Icon was replaced with an 'X' for this example.)

Is there an easy way to solve this issue?

.button.addcart {
    position: relative;
    padding: 0 29px 0 55px;
    font: 700 16px/40px 'Quattrocento Sans',sans-serif;
    text-decoration: none;
    color: #555;
    border-radius: 20px 0 0 20px;
    border: 2px solid #222;
    line-height: 48px!important;
    text-transform: uppercase;
    cursor: pointer;
}
.button.addcart:before {
    position: absolute;
    box-sizing: border-box;
    content: "X";
    top: 0;
    left: 0;
    width: 40px;
    height: 40px;
    border-radius: 20px;
    color: #555;
    margin: 3px 0;
    box-shadow: 0 0 0 3px #555, 0 0 0 9px #fff;
    font: normal normal normal 14px/1 FontAwesome;
    font-size: 26px;
    padding: 7px 0 0;
}
<button class="button addcart" id="add_to_cart689427" type="submit" name="addtocart" value="" title="add to cart">add to cart</button>


Solution

  • You may try radial-gradient to create a circle as a background over the background color then you can adjust its size and position to fill the missing border:

    .button.addcart {
        position: relative;
        padding: 0 20px 0 65px;
        font: 700 16px/40px 'Quattrocento Sans',sans-serif;
        text-decoration: none;
        color: #555;
        border-radius: 20px 0 0 20px;
        border: 2px solid #222;
        line-height: 48px!important;
        text-transform: uppercase;
        cursor: pointer;
        background: radial-gradient(circle at left,transparent 22%,#222 23%, #222 25%,transparent 25%) 19px 0px/131px 48px no-repeat,#ddd;
    }
    .button.addcart:before {
        position: absolute;
        box-sizing: border-box;
        content: "X";
        top: 0;
        left: 0;
        width: 40px;
        height: 40px;
        border-radius: 20px;
        color: #555;
        margin: 3px 0;
        box-shadow: 0 0 0 3px #555, 0 0 0 9px #fff;
        font: normal normal normal 14px/1 FontAwesome;
        font-size: 26px;
        padding: 7px 0 0;
    }
    <button class="button addcart" id="add_to_cart689427" type="submit" name="addtocart" value="" title="add to cart">add to cart</button>