Search code examples
htmlcsscss-shapes

How to draw error icon with css only,exactly like in the image


Im trying to do the following x icon, exactly the way it is in here:

enter image description here

So here is the html:

<div class='error-circle'>
    <div>X</div>
</div>

And here is the css:

.error-circle{
    width: 70px;
    height: 70px;
    background: #990000;
    border-radius: 100px;
    border: 4px solid white;
    color: white;
    font-size: 45px;
    font-weight: bold;
    padding-left: 17px;
}

It's close, but i really need the same result as the image (without the background), I think the X should not be the x character but two lines crossed one on the other, How should i achieve this result?


Solution

  • A real draw would look like this

    enter image description here

    *{box-sizing: border-box}
    :root{background: #ccc}
    div{
        width: 150px;
        height: 150px;
        border-radius: 50%;
        position: relative;
        margin: 40px auto;
        box-shadow: 0 0 0 10px white
    }
    
    div:before, div:after{
        content: ''; 
        position:absolute;
        width: 20px;
        height: 100px;
        left: 64px;
        top: 25px;
        background: white
    }
    div:before{
        transform: skew(28deg)
    }
    div:after{
        transform: skew(-28deg);
    }
    <div/>

    If you want it to look more real add some shadow

    *{box-sizing: border-box}
    :root{background: #ccc}
    div{
        width: 150px;
        height: 150px;
        border-radius: 50%;
        position: relative;
        margin: 40px auto;
        box-shadow: 0 0 0 10px white, 0 0 24px 12px #B3B3B3, inset 0 0 16px 1px #B3B3B3;
    }
    
    div:before, div:after{
        content: ''; 
        position:absolute;
        width: 20px;
        height: 100px;
        left: 64px;
        top: 25px;
        box-shadow: 0 0 16px 1px #B3B3B3;
        background: white
    }
    div:before{
        transform: skew(28deg)
    }
    div:after{
        transform: skew(-28deg);
    }
    <div/>

    The same result with a red background

    *{box-sizing: border-box}
    :root{background: #ccc}
    div{
        background: red;
        width: 150px;
        height: 150px;
        border-radius: 50%;
        position: relative;
        margin: 40px auto;
        box-shadow: 0 0 0 10px white, 0 0 24px 12px #B3B3B3, inset 0 0 16px 1px #B3B3B3;
    }
    
    div:before, div:after{
        content: ''; 
        position:absolute;
        width: 20px;
        height: 100px;
        left: 64px;
        top: 25px;
        box-shadow: 0 0 16px 1px #B3B3B3;
        background: white
    }
    div:before{
        transform: skew(28deg)
    }
    div:after{
        transform: skew(-28deg);
    }
    <div/>

    Now you are ready to use transform: scale(.5,.5); on div to have multiple sizes