You can use something called skew in the CSS transform declaration:
.fontToTransform { font-size: 40px; transform: skewX(15deg); -webkit-transform: skewX(15deg); -moz-transform: skewX(15deg); -o-transform: skewX(15deg); -ms-transform: skewX(15deg); }
This will save you the hassle of actually manipulating the font. This will turn the entire block into your text. You may need some kind of check to check each line break and split them into new tags every time. Since this may not be a real solution, you can take this into account if you want to cut a shorter (single-line) text.
Edit
This veeeery is far away, but here is a dirty example that detects individual lines in your text block and puts each of them in a new span , which will lead to the fact that each line will be separately decorated with the skewX style. Here you are:
CSS
#fontTransform { font-size: 40px; margin-right: 30px; text-align: right; } #fontTransform span { display: block; transform: skewX(15deg); -webkit-transform: skewX(15deg); -moz-transform: skewX(15deg); -o-transform: skewX(15deg); -ms-transform: skewX(15deg); }
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>HTML</title> <script src="jquery.js" type="text/javascript"></script> <script src="main.js" type="text/javascript"></script> <link rel="stylesheet" href="main.css" type="text/css" /> </head> <body> <p id="fontTransform">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p> </body> </html>
main.js
'use strict'; $(document).ready(function(){ var d = document.getElementById('fontTransform'); var t = d.innerHTML; var w = t.split(' '); var lines = []; d.innerHTML = w[0]; var height = d.clientHeight; var tmp_line = []; for (var i = 0; i < w.length; i++) { d.innerHTML = d.innerHTML + ' ' + w[i]; tmp_line[tmp_line.length] = w[i]; if (d.clientHeight > height) { height = d.clientHeight; console.log(w[i-1]); delete tmp_line[tmp_line.length-1]; lines[lines.length] = tmp_line; tmp_line = []; } } // Destroy d.innerHTML d.innerHTML = ''; var tmp_html = ''; // Refill the lines within spans for (var i = 0; i < lines.length-1; i++) { tmp_html = '<span>'; for (var x = 0; x < lines[i].length-1; x++) { tmp_html = tmp_html + lines[i][x] + ' '; } tmp_html = tmp_html.trim(); tmp_html = tmp_html + '</span>'; d.innerHTML = d.innerHTML + tmp_html; } });
You can use jQuery resize() binding to update blocks of text with percentile width. Also I'm not sure what happens with very long words that won't fit on one line. Not that this could actually happen, but keep in mind that this is unverified and can cause words to get lost. In fact, you need to do more tests for the actual publication.
user1467267
source share