Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Diagonal line through <div> or <span>

Tags:

I'm wanting to have a diagonal line drawn from the upper-right corner of a <div> or <span> to the lower-left corner. The problem is that the content will sometimes be longer or shorter. So, something like a static image won't work. Basically I want what's described here (How to create a diagonal line within a table cell?) but for a <div> or a <span>.

This has some interesting ideas: http://jsfiddle.net/zw3Ve/11/

So does this: http://css-tricks.com/forums/discussion/13384/diagonal-line/p1

This is kind of a retry at this post: How to strike through obliquely with css

I can't seem to figure any of this out though. It seems like a pure CSS solution should work here, but I just don't have the skills to make that happen. jQuery is an option for me as well.

like image 867
gtilflm Avatar asked Jul 11 '13 19:07

gtilflm


2 Answers

You can do this with an inline SVG background, using only CSS and no javascript.

.background {    // Draw an SVG top left to bottom right     background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' version='1.1' preserveAspectRatio='none' viewBox='0 0 10 10'> <path d='M0 0 L0 10 L10 10' fill='red' /></svg>");    background-repeat:no-repeat;    background-position:center center;    //scale it     background-size: 100% 100%, auto; } 

See my fiddle:

http://jsfiddle.net/3GWw2/

like image 91
Tristan Brotherton Avatar answered Sep 21 '22 21:09

Tristan Brotherton


Is first fiddle as example with image in background instead not good enough?

http://jsfiddle.net/zw3Ve/410/

.line {     display:inline-block;     border: 1px solid #ccc;     margin: 10px;     padding: 10px;     background:url(http://i.piccy.info/i7/c7a432fe0beb98a3a66f5b423b430423/1-5-1789/1066503/lol.png);     background-size:100% 100%; } 
like image 21
G-Cyrillus Avatar answered Sep 21 '22 21:09

G-Cyrillus