Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[zh-cn]: sync with content for white-space #23801

Merged
merged 7 commits into from
Oct 9, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 77 additions & 2 deletions files/zh-cn/web/css/white-space/index.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
---
title: white-space
slug: Web/CSS/white-space
l10n:
sourceCommit: 82877d5cf5a35e0a4d02b7c54aea0ce7d771d5cb
---

{{CSSRef}}

CSS **`white-space`** 属性用于设置如何处理元素内的{{Glossary("whitespace", "空白字符")}}。
**`white-space`** [CSS](/zh-CN/docs/Web/CSS) 属性用于设置如何处理元素内的{{Glossary("whitespace", "空白字符")}}。

{{EmbedInteractiveExample("pages/css/white-space.html")}}

fuchunhui marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -127,7 +129,7 @@ white-space: unset;
</tbody>
</table>

> **备注:** **空格**和**其他空白分隔符**之间存在区别。定义如下:
> [!NOTE] > **空格**和**其他空白分隔符**之间存在区别。定义如下:
fuchunhui marked this conversation as resolved.
Show resolved Hide resolved
>
> - 空格
> - : 空格(U+0020)、制表符(U+0009)和分段符(例如换行)
Expand Down Expand Up @@ -228,6 +230,78 @@ select.addEventListener("change", (e) => {

{{EmbedLiveSample("试试看", "100%", 350)}}
jasonren0403 marked this conversation as resolved.
Show resolved Hide resolved

### 在表格中控制换行
fuchunhui marked this conversation as resolved.
Show resolved Hide resolved

#### HTML

```html
<table>
<tr>
<td></td>
<td>拆分后非常长的内容</td>
<td class="nw">未拆分非常长的内容</td>
</tr>
<tr>
<td class="nw">white-space:</td>
<td>normal</td>
<td>nowrap</td>
</tr>
</table>
```

#### CSS

```css
table {
border-collapse: collapse;
border: solid black 1px;
width: 250px;
height: 150px;
}
td {
border: solid 1px black;
text-align: center;
}
.nw {
white-space: nowrap;
}
```

#### 结果

{{EmbedLiveSample("在表格中控制换行", "100%", "100%")}}

### SVG 文本元素的多行文本

`white-space` CSS 属性可用于在 {{SVGElement("text")}} 元素中创建多行文本,该元素默认情况下不会换行。

#### HTML

`<text>` 元素内部的文本需要拆分成多行以便检测新行。从第二行开始,其余行的空白需要移除。

```html-nolint
<svg viewBox="0 0 320 150">
<text y="20" x="10">Here is an English paragraph
that is broken into multiple lines
in the source code so that it can
be more easily read and edited
in a text editor.
</text>
</svg>
```

#### CSS

```css
text {
white-space: break-spaces;
}
```

#### 结果

{{EmbedLiveSample("SVG 文本元素的多行文本", "100%", 350)}}

## 规范

{{Specifications}}
Expand All @@ -239,3 +313,4 @@ select.addEventListener("change", (e) => {
## 参见

- 定义单词如何在*其内部*被截断的属性:{{CSSxRef("overflow-wrap")}}、{{CSSxRef("word-break")}}、{{CSSxRef("hyphens")}}
- [`tab-size`](/zh-CN/docs/Web/CSS/tab-size)