cssstrikethrough

CSS: Strike-through not centered through the text


We are using strike-through to actually show oldprice vs new price for a product.

If you open this link, at the bottom of the page, we have a product on sale. http://www.gkelite.com/Gymnastics-Shopby-GiftoftheWeek

The strike-through for the old price is not centered vertically for the text. Can any one help out as to why it's happening?


Solution

  • I found a solution for it utilizing psuedo elements http://jsfiddle.net/urjhN/

    .strike-center {
        position: relative;
        white-space: nowrap; /* would center line-through in the middle of the wrapped lines */
    }
    
    .strike-center:after {
        border-top: 1px solid #000;
        position: absolute;
        content: "";
        right: 0;
        top:50%;
        left: 0;
    }
    

    However this technique fails if the text is wrapped between lines, the line would be centered among those lines.

    It seems to work among all major browsers; for IE7 (and prior) you could just fallback to the classic line-through using conditional comments.