Search code examples
cssbuttontransitioneffectskew

CSS: Skew a buttons border, not the text


I'm looking for an easy way with a single tag (just <a>)to create a skew effect on the borders, but keep the text the way it is.

I would know how do with a span in- or outside, but I don't want to have additional, pretty much zero meaning HTML on the page.

Example below.

enter image description here


Solution

  • You can unskew the child element i.e. provide the opposite skew co-ordinates as you specified for the parent.

    Here is a working example

    Suppose you have below as you html,

    <div class="btn">
        <button><div class="btn-text">Click</div></button>
    </div>
    

    If we skew the parent element by 20deg then we should skew the child element by -20deg as,

    .btn {
        -ms-transform: skewX(20deg); /* IE 9 */
        -webkit-transform: skewX(20deg); /* Safari */
        transform: skewX(20deg);
    }
    .btn-text {
        -ms-transform: skewX(-20deg); /* IE 9 */
        -webkit-transform: skewX(-20deg); /* Safari */
        transform: skewX(-20deg);
        padding: 20px;
    }