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:"宋体";}1
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";}1
Or
body{font-family:"微软雅黑";}1
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).
Example
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>认识html标签</title><style type="text/css">body{ font-family:"Microsoft Yahei";}span{ font-family:"宋体";}</style></head><body> <h1 id="三年级">三年级</h1> <p>三年级<span id="stress">三年级</span>三年级</p> <p>三年级</p></body></html>1234567891011121314151617181920
Text layout – – Font size, color
You can use the following code to set the font size of the text in the web page to 12 px and set the font color to #666 (gray):
body{font-size:12px;color:#666}1
Example
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>字号、颜色</title><style type="text/css">body{font-size:12px;color:#666;}.stress{font-size:20px;color:red;}</style></head><body> <h1 id="三年级">三年级</h1> <p>三年级<span class="stress">三年级</span>三年级</p> <p>三年级<span>三年级</span>三年级</p></body></html>12345678910111213141516
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;}1
Here you can see that 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.
Example
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>粗体签</title><style type="text/css">p span{font-weight:bold;}a{font-weight:bold;}</style></head><body> <h1 id="三年级时">三年级时</h1> <p>三年级时<span class="stress">三年级时</span>三年级时<a href="http://www.imooc.com">三年级时</a>三年级时</p> <p>三年级时</p></body></html>12345678910111213141516
Text layout – – Italic
The following code can realize the text to be displayed in the browser in italic style :
p a{font-style:italic;}<p> 三年级 <a> 四年级 </a> 五年级 </p>12
Example
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>斜体样式</title><style type="text/css">p{ font-style:italic; }a{ font-weight: bold; color: red; font-style: normal;}</style></head><body><p>三年级<a>三年级</a>三年级</p> </body></html>1234567891011121314151617181920
Text layout – – Underline
In some cases, you want to set the underline style for text. This can visually emphasize the text, which can be achieved by using the following code:
p a{text-decoration:underline;}<p> 三年级 <a> 四年级 </a> 五年级 </p>12
Example
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>下划线样式</title><style type="text/css">a { text-decoration:underline; }span { text-decoration:underline;}</style></head><body><p><span>三年级</span><a> 四年级 </a> 五年级 </p></body></html>123456789101112131415161718
Text layout – – Strikethrough
What if you want to set a strikethrough on the web page? This style is often seen on e-commerce websites:
Use the following code to use the strikethrough on the original price in the picture above. You can achieve:
.oldPrice{text-decoration:line-through;}1
Example
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>删除样式</title><style type="text/css">.oldPrice{text-decoration:line-through;}</style></head><body><p>原价:<span class="oldPrice">300</span>元 现价:230 元</p> </body></html>12345678910111213
Paragraph layout – – Indentation
Pre-paragraph habits in Chinese text Empty the space between two texts. This special style can be achieved with the following code:
p{text-indent:2em;}<p>1922年的春天,一个想要成名名叫尼克卡拉威(托比?马奎尔Tobey Maguire 饰)的作家,离开了美国中西部,来到了纽约。那是一个道德感渐失,爵士乐流行,走私为王,股票飞涨的时代。为了追寻他的美国梦,他搬入纽约附近一海湾居住。</p>12
Note: 2em means 2 times the size of the text.
Example
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>缩进样式</title><style type="text/css">p{text-indent:2em;};</style></head><body> <h1 id="尼克-卡拉威">尼克?卡拉威</h1> <p>1922年的春天,一个想要成名名叫尼克?卡拉威(托比?马奎尔Tobey Maguire 饰)的作家,离开了美国中西部,来到了纽约。那是一个道德感渐失,爵士乐流行,走私为王,股票飞涨的时代。为了追寻他的美国梦,他搬入纽约附近一海湾居住。</p> <p>菲茨杰拉德,二十世纪美国文学巨擘之一,兼具作家和编剧双重身份。他以诗人的敏感和戏剧家的想象为"爵士乐时代"吟唱华丽挽歌,其诗人和梦想家的气质亦为那个奢靡年代的不二注解。</p></body></html>123456789101112131415
Paragraph layout – – Line spacing (line height)
In this section we will learn about another A line spacing (line height) attribute (line-height) that plays an important role in paragraph layout. The following code implements setting the paragraph line spacing to 1.5 times.
p{line-height:1.5em;}<p>菲茨杰拉德,二十世纪美国文学巨擘之一。</p>12
Example
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>行间距</title><style type="text/css">p{line-height:2em;}</style></head><body><p>菲茨杰拉德,二十世纪美国文学巨擘之一。</p></body></html>12345678910111213
Paragraph layout – – Chinese character spacing, letter spacing
Chinese character spacing, Letter spacing setting:
If you want to set text spacing or letter spacing in web page layout, you can use letter-spacing to Implementation, as shown in the following code:
h1{ letter-spacing:50px; }...<h1 id="了不起的乔布斯">了不起的乔布斯</h1>12345
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 id="welcome-nbsp-to-nbsp-iOS">welcome to iOS!</h1>12345
Example
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>字间距</title><style type="text/css">h1{ letter-spacing:20px;}</style></head><body><h1 id="hello-nbsp-world-你好">hello world!你好!</h1></body></html>123456789101112131415
Note
When setting the element to English, letter-spacing sets the spacing that is not English words , but the space between letters.
Paragraph layout – – Alignment
Want to set a centering style for text and images in block elements? You can use text-align style code. The following code can achieve centered display of text.
h1{ text-align:center/left/right; }<h1 id="了不起的乔布斯">了不起的乔布斯</h1>1234
Example
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>对齐</title><style type="text/css">div{ text-align:center;}</style></head><body><div><img src="/static/imghwm/default1.png" data-src="http://img.com/2000200.jpg" class="lazy" alt="CSS code formatting" ></div></body></html>123456789101112131415
The above is the detailed content of CSS code formatting. For more information, please follow other related articles on the PHP Chinese website!

在css中,可用list-style-type属性来去掉ul的圆点标记,语法为“ul{list-style-type:none}”;list-style-type属性可设置列表项标记的类型,当值为“none”可不定义标记,也可去除已有标记。

区别是:css是层叠样式表单,是将样式信息与网页内容分离的一种标记语言,主要用来设计网页的样式,还可以对网页各元素进行格式化;xml是可扩展标记语言,是一种数据存储语言,用于使用简单的标记描述数据,将文档分成许多部件并对这些部件加以标识。

在css中,可以利用cursor属性实现鼠标隐藏效果,该属性用于定义鼠标指针放在一个元素边界范围内时所用的光标形状,当属性值设置为none时,就可以实现鼠标隐藏效果,语法为“元素{cursor:none}”。

在css中,rtl是“right-to-left”的缩写,是从右往左的意思,指的是内联内容从右往左依次排布,是direction属性的一个属性值;该属性规定了文本的方向和书写方向,语法为“元素{direction:rtl}”。

在css中,可以利用“font-style”属性设置i元素不是斜体样式,该属性用于指定文本的字体样式,当属性值设置为“normal”时,会显示元素的标准字体样式,语法为“i元素{font-style:normal}”。

转换方法:1、给英文元素添加“text-transform: uppercase;”样式,可将所有的英文字母都变成大写;2、给英文元素添加“text-transform:capitalize;”样式,可将英文文本中每个单词的首字母变为大写。

在css3中,可以用“transform-origin”属性设置rotate的旋转中心点,该属性可更改转换元素的位置,第一个参数设置x轴的旋转位置,第二个参数设置y轴旋转位置,语法为“transform-origin:x轴位置 y轴位置”。


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.