× 目录 [1]white-space [2]word-wrap [3]word-break
前面的话
CSS3新增了两个换行属性word-wrap和word-break。把空白符和换行放在一起说,是因为实际上空白符是包括换行的,且常用的文本不换行是使用的空白符的属性white-space: nowrap;但到底它们还有些什么属性值,以及有什么对应的用法。本文将就空白符和换行的内容做详细介绍和梳理
空白符
定义
空白符是指空格、制表符和回车;HTML默认已经把所有空白符合并成一个空格。
white-space
值: normal | nowrap | pre | pre-wrap | pre-line | inherit
初始值: normal
应用于: 所有元素
继承性: 有
normal: 合并空白符,允许自动换行nowrap: 合并空白符,不允许自动换行pre-line: 合并空白符(不包括换行符),允许自动换行pre: 不合并空白符,不允许自动换行pre-wrap: 不合并空白符,允许自动换行
[注意]
元素默认带有样式white-space: pre; <p> [注意]IE7-浏览器不支持pre-line和pre-wrap这两个属性值</p> <p class="sycode"> <pre class='brush:php;toolbar:false;'><div>They can stay 72-hours within the Shandong province after they have entered China via the Qingdao International Airport.</div>
文本换行
浏览器自身带有文本自动换行的功能,文本容器的右侧可以实现自动换行
对于英文来说,浏览器会在半角空格或连字符的地方自动换行,而不会在单词的中间突然换行
对于中文来说,可以在任何一个文字后面换行,但浏览器碰到标点符号时,通常将标点符号以及其前一个文字作为一个整体进行换行
所以实际上,white-space解决不了长单词或UTL地址的换行问题
word-wrap
word-wrap属性用来实现长单词或URL地址的自动换行
值: normal | break-word
初始值: normal
应用于: 所有元素
继承性: 有
word-wrap:normal(浏览器只在半角空格或连字符的地方进行换行)word-wrap:break-word(截断单词换行,长单词从下一行开始)
[注意]当white-space的值是nowrap或pre时,word-break和word-wrap属性都失效
[注意]word-wrap在标准中被改为overflow-wrap,但由于兼容问题,一般还是使用word-wrap
word-break
CSS3使用word-break属性来决定自动换行的处理方法。通过具体的属性设置,不仅可以让浏览器实现半角空格或连字符后面的换行,而且还可以让浏览器实现任意位置的换行。
值: normal | break-all | keep-all
初始值: normal
应用于: 所有元素
继承性: 有
normal: 中文到边界上的汉字换行,英文从整个单词换行break-all: 对于英文长单词来说,会截断单词换行,长单词占据当前行剩余空间。但对于中文的处理,各浏览器不一致 [1]firefox及safari: 中文到边界上的汉字换行,且允许标点置于段首 [2]IE及chrome: 中文到边界上的汉字换行,但不允许标点置于段首keep-all: 对于英文长文本不能换行,但对于中文的处理,各浏览器不一致 [1]firefox: 在空白符处换行 [2]IE及chrome: 在空白符及标点处换行 [3]safari: 不支持
[注意]移动端目前基本都不支持keep-all值
[注意]当word-break值为break-all时,word-wrap属性失效;否则两个属性都起作用
表格
对于表单元格的长文本来说,使用word-wrap或word-break来强制换行需要设置table-layout:fixed

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1
Powerful PHP integrated development environment