Problem:
The <pre> tag of html is used to keep the format of the content as it is inputted. So, if the content is a long line of text with no line break, then it will displayed as one line and can be out of the container's scope. Even if we've already applied " word-wrap: break-word;" on the <div> outside the <pre>
This is surely ugly on the page. We expect a feature like notepad's auto line feed, so that when it is too long, it will wrap the line automatically.
Solution:
Add " word-wrap: break-word;" to the outside <div>
Apply the following css to <pre> tag.
pre {
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
}
Now it looks like this:
Try it with jsfiddle
- 大小: 5.5 KB
- 大小: 24.1 KB
分享到:
相关推荐
语言:English (United States) ... tags:pre { white-space: pre-wrap; }This takes effect immediately on all active pages.I've published the (very short) source code under the Apache 2.0 license.
In our example, if one transaction (T1) holds an exclusive lock at the table level, and another transaction (T2) holds an exclusive lock at the row level, each of the transactions believe they have ...
Header Files The #define Guard Header File Dependencies Inline Functions The -inl.h Files Function Parameter Ordering Names and Order of Includes Scoping Namespaces Nested Classes Nonmember, Static ...
In addition to the default Bochs method using the CTRL key and the middle mouse button there are now the choices: - CTRL+F10 (like DOSBox) - CTRL+ALT (like QEMU) - F12 (replaces win32 'legacyF12'...
By following these guidelines and exploring the integration techniques discussed in the webinar, Delphi developers can effectively leverage Python to enhance their applications and tap into its rich ...
有多种值可供选择,如 `normal`、`nowrap`、`pre`、`pre-line` 和 `pre-wrap` 等。在这里,我们需要的是 `pre-wrap` 值,它保留预格式化文本的空白字符,同时允许文本在必要时自动换行。 以下是一个示例 CSS 样式,...
white-space 属性值有多种,包括 `nowrap`、`pre`、`pre-wrap`、`pre-line` 等。其中,`pre-wrap` 属性值正是我们所需要的:保留空白符,保留换行符,允许自动换行。 在实际应用中,我们可以将容器元素设置为 `{...
For those unfamiliar with all the additions the AKBBS (now AIO) software has in comparison to the stock firmware, here's a sampling of the bigger changes: * Cheat Improvements - R4/XML Cheat File ...
支持图片的文字环绕 <br/>Locate the image you want to wrap text around, and click any justify button in the toolbar. The image will float to the desired direction. Text will be ...
此外,CSS还提供了其他技术来增强`<pre>`标签的功能,比如使用`overflow`属性处理超出容器宽度的文本,通过`line-numbers`伪类或者JavaScript库(如Prism.js或Highlight.js)实现代码高亮。对于大型代码块,可以使用...
- pre-line:合并空白符序列,并在必要时换行。 在IE6中,如果使用white-space:pre;,所有内容(包括长英文字符串)都会撑开容器。而使用white-space:nowrap;时,长英文字符串或中文长句都将在溢出容器时不会换行。...
1.4 Directives that can be omitted in pass 2 of the assembler 2 Overview of the ARM Architecture 2.1 About the ARM architecture 2.2 ARM, Thumb, and ThumbEE instruction sets 2.3 Changing between ARM, ...
而其他如 `-moz-pre-wrap`, `-hp-pre-wrap`, `-o-pre-wrap`, `-pre-wrap`, `pre`, 和 `pre-line` 是为了兼容早期的浏览器版本和特定环境,例如Mozilla Firefox、Opera等。 另外,还可以通过添加 `word-break: break...
常见的属性值包括:normal(默认,空白符被压缩,文本自动换行)、nowrap(不换行)、pre(保留空白符,按原格式显示)、pre-line(空白符被压缩,但文本会在换行符处换行)、pre-wrap(保留空白符,文本会在排满或...
white-space: pre-wrap; } #code-block .line-numbers { color: #999; padding-left: 1em; } #code-block code { display: block; padding: 0.5em; } ``` 3. **jQuery实现**:接下来,我们可以用...
比如,`-moz-pre-wrap` 是为了Firefox,而`-o-pre-wrap` 是为了Opera 7。 #### 五、浏览器兼容性 - **IE**: 使用`word-wrap: break-word;` - **Firefox**: 使用`white-space: -moz-pre-wrap;` - **Opera**: 使用`...
- `pre-line`:根据行内元素进行折行,每行的空白处理方式类似`normal`。 2. `word-break` 属性:这个属性用于决定单词在何处断开,以适应容器宽度。例如: - `normal`:遵循浏览器的默认断词规则。 - `break-...
pre-line 合并空白符序列,但是保留换行符。 inherit 规定应该从父元素继承 white-space 属性的值。 word-wrap:设置或检索当当前行超过指定容器的边界时是否断开转行。 normal 控制连续文本换行。 break-w
`pre-wrap`和`pre-line`在处理格式化文本时非常有用,但在某些旧版IE浏览器中可能不受支持。 除此之外,当文本内容超出容器时,我们还可以使用`text-overflow`属性结合`overflow`和`white-space`来实现文字溢出时...