Home > Article > Web Front-end > How to Achieve Left-Aligned Text on a Slanted Line in All Browsers?
Achieving left-aligned text on a slanted line can pose a challenge, particularly when seeking cross-browser compatibility (back to IE9).
By introducing a series of square elements and calculating their sizes, we can create an effective solution:
<code class="less">.loop(@i) when (@i > 0){ .loop((@i - 1)); .space@{i}{ width: floor(@i*@hSize/(1/tan(5deg))); } } @hSize: 15px; .space { float: left; clear: left; width: @hSize; height: @hSize; }</code>
In HTML, we incorporate these elements as follows:
<code class="html"><p> <span class="space space1"></span> <span class="space space2"></span> <!-- (...) --> <span class="space space11"></span> Lorem ipsum dolor sit amet. Vestibulum commodo volutpat a, convallis ac, laoreet enim. Phasellus fermentum in, dolor. Pellentesque facilisis. Nulla imperdiet sit amet magna. Vestibulum dapibus, mauris nec malesuada fames ac turpis velit, rhoncus eu, luctus et interdum adipiscing wisi. Aliquam erat ac ipsum. Integer aliquam purus. Quisque lorem tortor fringilla sed, vestibulum id, eleifend justo vel bibendum sapien massa ac turpis faucibus orci luctus non, consectetuer lobortis quis, varius in, paragraph. </p></code>
This LESS-based solution provides a cross-browser compatible approach to achieve left-aligned text on a slanted line.
The above is the detailed content of How to Achieve Left-Aligned Text on a Slanted Line in All Browsers?. For more information, please follow other related articles on the PHP Chinese website!