I need something like this:
How can achieve this with css? I know that one way is use background image, but can I achieve this only with css without any image?
You can also use the <del> tag for crossed-out text, which is more semantically correct. However, the <del> tag doesn't always work in all browsers. So, if you need to ensure that your text is readable in any browser, the <strike> tag is a good fallback. CSS can also be used to style strikethrough text.
In order to make oblique lines with CSS, there are two main approaches. The first approach involves the clip-path property of CSS and in the second approach, we use transform property with skew() of CSS. Approach 1: Using clip-path property: The clip-path property is generally used to clip an element to a basic shape.
In the same manner as underlining a text, you can do a strikethrough, where a horizontal line goes through the text. Strikethrough/line through can only be done in one way: STYLE="text-decoration: line-through". The style has to be used on a tag for text sections, e.g. <P>, <DIV> and <SPAN>.
If you can see your new CSS in the Styles pane, but your new CSS is crossed out, it means that there's some other CSS that is overriding your new CSS. In CSS terminology this concept is called Specificity. Chrome DevTools can help you find the old CSS that is causing your new CSS to not be applied.
There is a hacky way to do this, using the :before
pseudo element. You give the :before
a border, then rotate it with a CSS transform. Doing it this way adds no extra elements to the DOM, and adding/removing the strikethrough is a simple as adding/removing the class.
Here's a demo
:before
, however will degrade gracefully in browsers that do support :before
but don't support CSS transforms..strikethrough {
position: relative;
}
.strikethrough:before {
position: absolute;
content: "";
left: 0;
top: 50%;
right: 0;
border-top: 1px solid;
border-color: inherit;
-webkit-transform:rotate(-5deg);
-moz-transform:rotate(-5deg);
-ms-transform:rotate(-5deg);
-o-transform:rotate(-5deg);
transform:rotate(-5deg);
}
<span class="strikethrough">Deleted text</span>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With