search
HomeWeb Front-endHTML TutorialA few things about text attributes of CSS basics_html/css_WEB-ITnose

line-height

You can specify a scaling factor without a unit for an element, so that its descendant elements will inherit this scaling factor and then adjust it according to their own font size To calculate your own line-height value,

body {  font-size: 12px;  line-height: 1.5;}h1 {  font-size: 36px;}

Here, the line-height of body is 18px (12 * 1.5), and the line-height of h1 is is 54px (36*1.5).

Even if relative units such as em and percentage are used, descendant elements still inherit the calculated line-height (line-height) value. For example, if the line-height of the body above is changed to 1.5em, then the line-height of h1 Will inherit this value 18px.

text-decoration

Text decoration is a non-inherited class attribute. Setting it to none for the body element will not affect the elements in the descendants that have text decoration by default, such as Hyperlink, so if you want to remove the default underline of the hyperlink, you still need to set it separately.

a {  text-decoration: none;}

Although this attribute is not inherited by default, the modification set on the ancestor element will "extend" ” into the descendant elements,

<p>我有下划线 <span>我咋会有下划线呢?</span></p>

p {  color: red;  text-decoration: underline;}p span {  color: green;  text-decoration: none;}

The underscore here is for the p element.

p {  color: red;  text-decoration: underline;}p span {  color: green;  text-decoration: underline;}

Here the underline of span covers the underline of p.

p {  color: red;  text-decoration: underline;}p span {  color: green;  text-decoration: overline;}

Since the extension of text decoration attributes will cause some compatibility issues,

The best way is to set the text-decoration attribute separately for the text that needs to be modified.

text-indent

You can use this attribute to indent the first line of each paragraph by 2 characters instead of using spaces,

p {  text-indent: 2em;}

You can also specify a negative value to produce the effect of the first row hanging,

text-indent: -3em;

Let Hanging quotation marks is also a common practice,

Indent the text to a place far enough that the text disappears,

text-indent: -9999px;

Therefore, the usual method of replacing text on images,

.logo {  background: url(logo.png) no-repeat;  display: inline-block;  height: 36px;  text-indent: -9999px;  width: 72px;}

IE6/7 does not really support inline-block, and in some cases may cause the .logo to disappear. You can Use float or block instead of inline-block, but both will change the layout, and other methods can also be used.

text-overflow

Normally, a long string of URL addresses will overflow when it exceeds the container. We can set it to be omitted when the text overflows the containing container. Symbols,

li {  overflow: hidden;  text-overflow: ellipsis;}

must be used together with overflow: hidden;; sometimes you may have to add a width, such as IE 6,

For those texts that do not overflow by default, you need to force them to be displayed in one line in order to have an effect.

li {  overflow: hidden;  text-overflow: ellipsis;  <strong>white-space</strong>: <strong>nowrap</strong>;  width: 100%; /* for IE 6 */ }

Use white-space: pre; or word-break: keep-all; can also force the text to be displayed on one line, but each has its own problems.

In IE 8/9, sometimes you will find that it has no effect. It may be that one of the ancestor elements has word-wrap: break-word; and this attribute will perform better than white-space : nowrap; is more powerful, so sometimes you have to add the following code,

word-wrap: normal;

text-shadow

in non-white You can achieve beautiful inline effects on dark text on the background.

text-shadow: 0 1px 0 rgba(255,255,255,.75);

You can add multiple shadows to the text, separated by commas,

text-shadow: 0 1px 0 #fff, 0 2px 0 #ddd, 0 3px 0 #ddd, 0 4px 0 #ddd;

white-space

The white-space attribute sets how to handle whitespace within the element.

Set the value to nowrap so that the text can continue on the same line and will not wrap when it encounters a boundary until it encounters the
tag,

white-space: nowrap;

Sometimes we want to retain spaces and line breaks in the text. For example, when displaying computer source code,

 will be used, and the value of the white-space attribute of <pre class="brush:php;toolbar:false"> is pre,  <p class="sycode"> <pre class='brush:php;toolbar:false;'>pre {  white-space: pre;}

pre is not so satisfactory. It will not automatically wrap when encountering a boundary, so CSS 2.1 adds pre-wrap,

pre {  white-space: pre;  white-space: pre-wrap;}

In this way, the content in the pre element can not only maintain the original format, but also automatically wrap when the content exceeds the boundary.

Since not all browsers support pre-wrap, you need to force those browsers that do not support line breaks,

pre {  white-space: pre;  white-space: pre-wrap;  <strong>word-wrap</strong>:<strong> break-word</strong>;}

Of course, maybe you don’t If you want line breaks and don’t mind horizontal scroll bars, you can use horizontal scroll bars to replace line breaks,

pre {  overflow: auto;}

word-break

Currently, the webkit family (including Google Chrome, Safari, Android Browser, etc.) does not support the keep-all value, so the only one that can be used is break-all,

word-break: break-all;

However, it will cause difficulties in reading English text and should be used with caution,

 

word-wrap

这是比 word-break 更好的实现文本换行的方式,

word-wrap: break-word;

再添加一个溢出隐藏,避免一些恶意的连续字符,

overflow: hidden;

 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
HTML: Building the Structure of Web PagesHTML: Building the Structure of Web PagesApr 14, 2025 am 12:14 AM

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.

From Text to Websites: The Power of HTMLFrom Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AM

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.

Understanding HTML, CSS, and JavaScript: A Beginner's GuideUnderstanding HTML, CSS, and JavaScript: A Beginner's GuideApr 12, 2025 am 12:02 AM

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

The Role of HTML: Structuring Web ContentThe Role of HTML: Structuring Web ContentApr 11, 2025 am 12:12 AM

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

HTML and Code: A Closer Look at the TerminologyHTML and Code: A Closer Look at the TerminologyApr 10, 2025 am 09:28 AM

HTMLisaspecifictypeofcodefocusedonstructuringwebcontent,while"code"broadlyincludeslanguageslikeJavaScriptandPythonforfunctionality.1)HTMLdefineswebpagestructureusingtags.2)"Code"encompassesawiderrangeoflanguagesforlogicandinteract

HTML, CSS, and JavaScript: Essential Tools for Web DevelopersHTML, CSS, and JavaScript: Essential Tools for Web DevelopersApr 09, 2025 am 12:12 AM

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

The Roles of HTML, CSS, and JavaScript: Core ResponsibilitiesThe Roles of HTML, CSS, and JavaScript: Core ResponsibilitiesApr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

Is HTML easy to learn for beginners?Is HTML easy to learn for beginners?Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment