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?
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?
I did it this way using an SVG in the HTM with a CSS class:
HTML:
CSS:
There might be simpler easier ways by now. I just cooked this up in a pinch for my product detail special offer page. Hope it helps someone.
You can use background
linear-gradient
withcurrentColor
to avoid hardcoding font color:If you don't need the element to be fully inline, you can use a pseudo element to place the line on top of the element. This way the angle can be adjusted by changing the pseudo element's size:
I don't think there is a sustainable css solution to this.
My pure CSS solution would be to place another element of text behind your first element of text that is identical in number of characters (characters being ' '), a text-decleration of line-through, and a transform of rotate.
Something like:
Text Rotation example
I am looking forward to seeing better answers from other users.
This is an old question but as an alternative you can use CSS3 Linear Gradients for example (http://codepen.io/yusuf-azer/pen/ojJLoG).
For extensive explaining and a LESS Solution check
http://www.yusufazer.com/tutorials-how-to/how-to-make-a-diagonal-line-through-with-css3/
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
Caveats
:before
, however will degrade gracefully in browsers that do support:before
but don't support CSS transforms.CSS
HTML
I think you could probably apply a rotation effect to a horizontal rule. Something like:
With the CSS:
Fiddle
Your mileage may vary depending on browser and version though, so I'm not sure if I'd resort to this. You might have to pull off some funky VML code to support older versions of IE, for example.