Home Web Front-end CSS Tutorial [CSS Notes 5] CSS formatting and typesetting

[CSS Notes 5] CSS formatting and typesetting

Dec 29, 2016 pm 01:50 PM

1. Text layout: font
We can use css styles to set font, font size, color and other style attributes for the text in the web page. Let's take a look at an example. The following code implements: setting the font to Song Dynasty for the text in the web page.

body{font-family:"宋体";}
Copy after login

Be careful not to set uncommon fonts here, because if the fonts you set are not installed on the user's local computer, the browser's default fonts will be displayed. (Because whether the user can see the font style you set depends on whether the font you set is installed on the user's local computer.)
Nowadays, most web pages like to set "Microsoft Yahei", as follows:

body{font-family:"Microsoft Yahei";}
Copy after login

or

body{font-family:"微软雅黑";}
Copy after login

Note: The first method is more compatible than the second method.

Because this font is beautiful and can be displayed safely on the client (it is usually installed by default locally).

2. Text layout: font size, color
You can use the following code to set the font size of the text on the web page to 12 pixels, and set the font color to #666 (gray):

body{font-size:12px;color:#666}
Copy after login

3. Text layout: bold
We can also use css styles to change the text style: bold, italic, underline, strikethrough. You can use the following code to set the text to be displayed in bold style.

p span{font-weight:bold;}
Copy after login

If you want to set bold text for text, there is a separate css style to achieve it. You no longer need to use h1-h6 or strong tags to achieve bold style.

4. Text layout: italics
The following code can realize the text to be displayed in italics in the browser:

p a{font-style:italic;} <p>三年级时,我还是一个<a>胆小如鼠</a>的小女孩。</p>
Copy after login

5. Text layout: underline
In some cases Next, I want to set the underline style for the text, so that the text can be visually emphasized. You can use the following code to achieve this:

p a{text-decoration:underline;} <p>三年级时,我还是一个<a>胆小如鼠</a>的小女孩。</p>
Copy after login

6. Text layout: strikethrough
Use the following code to strikethrough Can be realized:

.oldPrice{text-decoration:line-through;}
Copy after login

7. Paragraph typesetting: indentation
In Chinese text, it is customary to leave two spaces before a paragraph. This special style can be achieved with the following code:

p{text-indent:2em;} <p>1922年的春天,一个想要成名名叫尼克卡拉威(托比?马奎尔Tobey Maguire 饰)的作家,离开了美国中西部,来到了纽约。
那是一个道德感渐失,爵士乐流行,走私为王,股票飞涨的时代。为了追寻他的美国梦,他搬入纽约附近一海湾居住。</p>
Copy after login

Note: 2em means twice the size of the text.

8. Paragraph layout: line spacing (line height)
The line spacing (line height) attribute (line-height) that plays an important role in paragraph layout, the following code implements setting paragraph lines The spacing is 1.5 times.

p{line-height:1.5em;} <p>菲茨杰拉德,二十世纪美国文学巨擘之一,兼具作家和编剧双重身份。他以诗人的敏感和戏剧家的想象为"爵士乐时代"吟唱华丽挽歌,
其诗人和梦想家的气质亦为那个奢靡年代的不二注解。</p>
Copy after login

9. Paragraph typesetting: Chinese character spacing and letter spacing
If you want to set text spacing or letter spacing in web page layout, you can use letter-spacing to achieve it, as shown in the following code:

h1{ letter-spacing:50px; } ... <h1>了不起的盖茨比</h1>
Copy after login

Note: When this style is used in English words, it sets the spacing between letters.

Word spacing setting:

What if I want to set the spacing between English words? This can be achieved using word-spacing. The following code:

h1{ word-spacing:50px; } ... <h1>welcome to imooc!</h1>
Copy after login

10. Paragraph layout: alignment
Want to set a centering style for text and pictures in block elements? You can use text-align style code. The following code can achieve centered display of text.

h1{ text-align:center; } <h1>了不起的盖茨比</h1>
Copy after login

You can also set it to the left:

h1{ text-align:left; } <h1>了不起的盖茨比</h1>
Copy after login

You can also set it to the right:

h1{ text-align:right; } <h1>了不起的盖茨比</h1>
Copy after login

The above is the CSS format of [CSS Notes 5] For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement of this Website
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

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

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Vue 3 Vue 3 Apr 02, 2025 pm 06:32 PM

It&#039;s out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

Can you get valid CSS property values from the browser? Can you get valid CSS property values from the browser? Apr 02, 2025 pm 06:17 PM

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That&#039;s like this.

A bit on ci/cd A bit on ci/cd Apr 02, 2025 pm 06:21 PM

I&#039;d say "website" fits better than "mobile app" but I like this framing from Max Lynch:

Stacked Cards with Sticky Positioning and a Dash of Sass Stacked Cards with Sticky Positioning and a Dash of Sass Apr 03, 2025 am 10:30 AM

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

Using Markdown and Localization in the WordPress Block Editor Using Markdown and Localization in the WordPress Block Editor Apr 02, 2025 am 04:27 AM

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

Comparing Browsers for Responsive Design Comparing Browsers for Responsive Design Apr 02, 2025 pm 06:25 PM

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Apr 05, 2025 pm 05:51 PM

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...

How to Use CSS Grid for Sticky Headers and Footers How to Use CSS Grid for Sticky Headers and Footers Apr 02, 2025 pm 06:29 PM

CSS Grid is a collection of properties designed to make layout easier than it’s ever been. Like anything, there&#039;s a bit of a learning curve, but Grid is

See all articles