首页 >web前端 >css教程 >IE9 中文本可以沿斜线左对齐吗?

IE9 中文本可以沿斜线左对齐吗?

Mary-Kate Olsen
Mary-Kate Olsen原创
2024-11-01 17:58:02382浏览

 Can text be left-aligned along a slanted line in IE9 ?

在斜线上对齐文本

文本可以沿斜线左对齐吗?对齐方式应符合倾斜形状,兼容 IE9 浏览器。

考虑以下代码示例:

<code class="html"><img src="http://placehold.it/150x250&text=img" alt="image" />
<p>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>
<code class="css">img {
  display: block;
  float: left;
  transform: rotate(-5deg);
  margin: 0 15px;
}</code>

解决方案:使用 LESS

作为标准 CSS 方法的补充,一种更非常规的解决方案包括添加方形元素并计算其大小:

<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>

HTML 如下:

<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>

;概念证明:

这里有一个实际示例来演示实际的解决方案:http://codepen.io/Tymek/pen/jEypOX?editors=110

以上是IE9 中文本可以沿斜线左对齐吗?的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn