增加字体和颜色样式-CSS_html/css_WEB-ITnose
通过使用CSS,控制文本的字体,风格和颜色
1.基本操作:
1 body{ 2 font-family: Verdana, Geneva, Tahoma, sans-serif 3 } 4 5 body{ 6 font-size: 14px 7 } 8 9 body{10 color: silver11 }12 13 body{14 font-weight: bold15 }16 17 body{18 text-decoration: underline19 }
注释:
2.字体系列:
系列分类:
示例:
总结特点:
3.使用CSS指定字体系列:
浏览器的幕后工作:
1 body{2 font-family: Verdana, Geneva, Tahoma, sans-serif3 }
注释:
示图:
4.Wed字体的使用
我们都会有这样一个想法,
自己辛苦设计的页面,有很酷的字体,
不希望到了用户手里,却全都变成了默认。。。
因此:有了@font-face规则
使用步骤:
- 找到一个字体,可以是自己所有的,也可以使用提供字体网站授权给你使用的
- 确保有所需字体的格式,一般建议使用web开放字体格式(.woff)
- 把字体文件放在web上,或者利用在线字体服务为你托管这些文件。但无论哪种,你都需要字体文件的URL
- 在CSS中增加@font-face属性
- 在CSS中使用@font-face属性
示例代码:
1 @font-face{ 2 /*我们为我们的字体设立一个名字*/ 3 font-family: "JJStyle One"; 4 /*浏览器会加载src指定的字体文件,直到找到他能支持的一个文件*/ 5 src: ur1("http://wickedlysmart.com/hfhtmlcss/chapter8/journal/EmblemaOne-Regular.woff") 6 ur1("http://wickedlysmart.com/hfhtmlcss/chapter8/journal/EmblemaOne-Regular.ttf") 7 } 8 9 10 h1{11 /*使用我们指定的字体名*/12 font-family: "JJStyle One",sans-serif;13 }
注意:
5.调整字体大小
大多数默认的字体都不太美观,
为此,作为设计者,
都需要知道如何指定字体大小。
指定font-size的一些方法:
- PX
- %
- em
- 关键字
示例代码:
1 body{ 2 /*字体的高度为14像素*/ 3 font-size: 14px 4 } 5 6 h1{ 7 /*字体大小为相对于另一个字体大小的150%,这里是相对于body字体的大小*/ 8 font-size:150% 9 }10 11 h2{12 /*相对于另一个字体1.2倍*/13 font-size: 1.2em;14 }15 16 h3{17 font-size: small18 /*关键字有:xx-small,x-small,small,medium,large,x-large,xx-large*/19 }
指定字体大小的建议:
- 选择一个关键字(推荐samll或mediun),指定它为body规则的字体大小。相当于页面默认大小
- 使用em或百分数,相对于body字体大小指定其它元素的字体大小(使用em还是百分数由你决定,因为效果都一样)
1 body{ 2 font-family: Verdana, Geneva, Tahoma, sans-serif; 3 /*字体的高度为14像素*/ 4 font-size: small 5 } 6 7 h1{ 8 font-family: sans-serif; 9 /*字体大小为相对于另一个字体大小的150%,这里是相对于body字体的大小*/10 font-size:150%11 }12 13 h2{14 /*相对于另一个字体1.2倍*/15 font-size: 1.2em;16 }
示图:
6.改变字体粗细:
7.为字体增加风格:
斜体:
- not italic
- italic(文本向右倾斜,另外衬线还有弯曲)
倾斜:
- not oblique
- oblique(普通文本向右倾斜)
注意:
8.颜色样式:
指定颜色的方法:
1.按名字指定
1 body{2 background-color: silver;<br />3 }
2.用红绿蓝值指定颜色
1 body{2 /*rgb:红绿蓝 颜色的缩写*/3 background-color: rgb(80%, 40%, 0%);4 }5 h1{6 background-color: rgb(204,102,0);7 }
3.用16进制码指定
1 h2{2 background-color: #cc66003 }
注释:
文本装饰:
1 em{ 2 /*使<em>元素有一个从文本中间穿过的横线*/ 3 text-decoration: line-through; 4 } 5 6 7 em{ 8 /*使<em>元素有一个上画线和下划线*/ 9 text-decoration: underline overline;10 }11 12 em{13 /*使<em>元素没有任何装饰*/14 text-decoration: none;15 }16 17 h1,h2{18 color: #cc6600;19 /*在下滑框上加一条细的虚线*/20 border-bottom:thin dotted #aabbcc;21 }
The end--

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











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 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 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.

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

To build a website with powerful functions and good user experience, HTML alone is not enough. The following technology is also required: JavaScript gives web page dynamic and interactiveness, and real-time changes are achieved by operating DOM. CSS is responsible for the style and layout of the web page to improve aesthetics and user experience. Modern frameworks and libraries such as React, Vue.js and Angular improve development efficiency and code organization structure.

The article discusses the differences between HTML tags , , , and , focusing on their semantic vs. presentational uses and their impact on SEO and accessibility.

The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.
