CSS使文章自动换行的问题

1. 在table中只需在样式中加入 word-break:break-all即可

如:

<table style="table-layout:fixed">
<tr>
<td width="100" style="word-break:break-all">Mistletoe also known throughout history as the golden bough has several different legends associated with its beginning and its meaning.

 2. 在div

页面代码:

<div class="fontSize-black14">
    <span class="css_lineheight180"><s:text name="softwDevlpBean.content"></s:text></span>
</div>

CSS代码:

.fontSize-black14 {
 font-size: 14px;
 color:black;
 margin-right:6px;
 margin-left: 6px;
 padding-top: 6px;
 word-break:break-all;
}

.css_lineheight180
{
 line-height:185%;      /* 将行加高 */
 margin-right:8px;
 margin-left: 8px;
 
}
.css_lineheight180 p
{
 overflow:auto;
 margin-bottom: 12px;
}
.css_lineheight180 pre{
white-space:pre-wrap;
white-space:-moz-pre-wrap;
white-space:-pre-wrap;
white-space:-o-pre-wrap;
word-wrap:break-word;
}

 

说明一下html中的pre标签:

定义和用法

pre 元素可定义预格式化的文本。被包围在 pre 元素中的文本通常会保留空格和换行符。而文本也会呈现为等宽字体。

<pre> 标签的一个常见应用就是用来表示计算机的源代码。

可以导致段落断开的标签(例如标题、<p><address> 标签绝不能包含在 <pre> 所定义的块里。尽管有些浏览器会把段落结束标签解释为简单地换行,但是这种行为在所有浏览器上并不都是一样的。

pre 元素中允许的文本可以包括物理样式和基于内容的样式变化,还有链接 标签" href="http://www.w3school.com.cn/tags/tag_img.asp">图像水平分隔线。当把其他标签(比如 <a> 标签)放到 <pre> 块中时,就像放在 HTML/XHTML 文档的其他部分中一样即可。请看下面的例子:

	<pre>
&lt;html&gt;

&lt;head&gt;
  &lt;script type=&quot;text/javascript&quot; src=&quot;loadxmldoc.js&quot;&gt;
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;

  &lt;script type=&quot;text/javascript&quot;&gt;
    xmlDoc=<a href="dom_loadxmldoc.asp">loadXMLDoc</a>(&quot;books.xml&quot;);
    document.write(&quot;xmlDoc is loaded, ready for use&quot;);
  &lt;/script&gt;

&lt;/body&gt;

&lt;/html&gt;
</pre>

在上面的代码中,<pre> 标签中的特殊符号被转换为符号实体,比如 "&lt;" 代表 "<","&gt;" 代表 ">"。另外,请注意蓝色的代码,我们在 <pre> 标签中使用了链接,也就是 <a> 标签。上面这段代码的显示效果如下:

	<html>

<head>
  <script type="text/javascript" src="loadxmldoc.js">
</script>
</head>

<body>

  <script type="text/javascript">
    xmlDoc=loadXMLDoc("books.xml");
    document.write("xmlDoc is loaded, ready for use");
  </script>

</body>

</html>

提示和注释

提示:制表符(tab)在 <pre> 标签定义的块当中可以起到应有的作用,每个制表符占据 8 个字符的位置。但是我们不推荐使用它,因为在不同的浏览器中,Tab 的实现各不相同。在用 <pre> 标签格式化的文档段中使用空格,可以确保文本正确的水平位置。

提示:如果您希望使用 <pre> 标签来定义计算机源代码,比如 HTML 源代码,请使用符号实体来表示特殊字符,比如 "&lt;" 代表 "<","&gt;" 代表 ">","&amp;" 代表 "&"。

提示:在 W3School 中,非常多页面中的源代码实例都是通过 <pre> 标签定义的,您可以参考这些页面,学习如何使用该标签。我们甚至把 <pre> 标签与 <code> 标签结合起来使用,以获得更加精确的语义。

posted @ 2012-10-14 00:03  wj-conquer  阅读(505)  评论(0编辑  收藏  举报