search
HomeWeb Front-endCSS TutorialCSS3--How to add font and color styles to text

This chapter can make the text in your web page more beautiful

About some properties of text

  • font-family: Text font

  • font-size: Text size

  • color: Text color

  • ##font- weight: text thickness

  • text-decoration: more styles of text

  • ##font-family(font family)

There are five series in total: sans-serif (no serif), serif (serif), monospace (equal width), cursive (cursive... this is the original intention), fantasy ( Fantasy?) See the image on the right
##How does font-family work in CSS

##
body {
	font-family: Verdana, Geneva, Arial, sans-serif;
}

Check if there is Verdana in the client's computer. If so, use Verdana to display the text. If not, check if there is Geneva. If not, check for Arial. If still not, check if there is sans-serif in the client. Font (generally every computer has a sans-serif font. Note: sans-serif is not a specific font) If the font name contains spaces, you can put that Add quotation marks around the name, like this: font-family: "Courier New", Courier;
If I really want users to be able to use the font I specify, but I don’t know if the user has this font

Web font is here!

How to use

#Find a font file: the suffix name is woff, svg, eot, otf, ttf
  1. To place this font on the web, you can use Google's font hosting service, which is free

  2. Add the @font-face attribute in CSS

    @font-face {
    	font-family:"Emblema One";
    	src:url("www.某网站.com");
    }/*那个网址就是字体URL */
  3. At this time, it is equivalent to creating a font named Emblema One on the user machine
  4. Use it like a local font. Note that the place where you use the font must be @font After -family

  5. #The disadvantage of this is that loading the font will take a while, so the first time a customer visits your website and he does not have this font, he will Take a moment
Adjust the font size

There are three font units: px (pixel), %, em (which is a multiple, em=% divided by 100 )
h1 {
	font-size:220%;
}

There is also a way to specify the font size - keywords (xx-small, x-small, small, medium, large, x-large, xx-large)The size represented by each keyword is not necessarily certain, this has something to do with the client
So, how should I specify the size of the text

First of all, you can define the text size of through keywords. Through keywords, you can get the default size on the client side, which is the commonly used size on the other side.

After that, use percentage or em to adjust the size of other text (such as first-level titles) relative to the text size of . It is not recommended to use px pixels here
Font size, although you can accurately determine the size of the text, scaling will not be supported in older versions of IE browsers
Change font thickness

There are five keyword sizes, namely: bold (bold), bolder (thicker), inherit (inherit the thickness of the previous level), lighter (thinner), normal ( Ordinary)

There is also a way to set the font-weight to a number between 100 and 900 (a multiple of 100 )
Add style to the font

There are four types: inherit (inherit dad), italic (italic), normal (normal), oblique (inclined)

The difference between italic and oblique is that the former uses the italics of this font and is displayed in the font file, while the latter directly italics the regular words. . . But it seems to be about the same

颜色

Demo设置的颜色
body {
	background-color:red;
	background-color:rgb(80%, 40%, 0%);
	background-color:rgb(204, 102, 0);
	background-color:#66ccff;
}
这是四种设置颜色的方法,第一种是关键字,这个一般是小学生在用的吧,支持的颜色不多
第二种是使用rgb(red、green、blue)百分比,那些百分比意思是依次是红/绿/蓝的量(怎么说呢,越大就越含有这个颜色)
第三种和第二种相似,只不过从0%~100%改成了0~255
最后一种是十六进制码,意思是:
前两个代表红的十六进制、中间两个是绿的、最后两个是蓝的
把十六进制转成10机制就变成了第三种设置颜色的方法了

对于文本和背景,要使用对比度比较大的颜色,这样可读性才好













文本装饰(text-decoration)

    不多说,直接看效果:blink inherit line-through none overline underline

BULLET POINTS

  • CSS provides many properties to control the appearance of fonts, including font-family, font-weight, font-size, font-style, etc.

  • font-family is a group of fonts with common characteristics

  • Font families used for the Web include serif, sans-serif, monospace, cursive , fantasy. serif and sans-serif are most commonly used

  • The fonts your visitors see on your web pages depend on what fonts are installed on their own computers, unless you use web fonts

  • It is a good idea to specify candidate fonts in the font-family CSS property in case the user does not have your preferred font installed

  • The last font to be For a generic font, such as serif or sans-serif, so that if it cannot find another font, the browser can substitute the appropriate font

  • If you want to use a certain font, While users may not have this font installed by default, you can use @font-face rules

  • The font size is usually specified by keywords, pixels px, percentage, em

  • If you use pixels to specify the font size, you are telling the browser how many pixels the letter height is

  • ##em and % are relative font sizes, so use em When specifying a font size with %, it means that the font size is determined relative to the font size of its parent element

  • Using relative font sizes can make your page more maintainable

  • Use the font size keyword in the body rule to set the base font size so that if the user wants the text to be larger or smaller, all browsers can scale the font size proportionally

  • You can use the font-weight CSS property to make text bold

  • The font-style property is used to create italic or italic text. Italic or italic text is slanted

    CSS3--How to add font and color styles to text

  • Web colors are obtained by mixing different amounts of red, green, and blue

  • If Mix red 100%, green 100%, blue 100% to get white, all 0% is black

  • There are 16 basic colors in CSS, and more than 150 extended colors

  • You can use red, green, and blue percentages to specify the color you want, or you can use numerical values ​​(0~255), or hexadecimal codes

  • To find the hexadecimal code for the color you want, use the color picker tool in your image editing application.

  • The hexadecimal code representing a color has 6 digits. Each bit is indexed from 0 to F. The first two represent the number of red, the middle two are green, and the last two are blue.

  • You can use the text-decoration attribute Create an underscore for this. Underlined documents are often mistaken for link text by users, so use this attribute with caution

#

The above is the detailed content of CSS3--How to add font and color styles to text. For more information, please follow other related articles on the PHP Chinese website!

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
What is CSS Grid?What is CSS Grid?Apr 30, 2025 pm 03:21 PM

CSS Grid is a powerful tool for creating complex, responsive web layouts. It simplifies design, improves accessibility, and offers more control than older methods.

What is CSS flexbox?What is CSS flexbox?Apr 30, 2025 pm 03:20 PM

Article discusses CSS Flexbox, a layout method for efficient alignment and distribution of space in responsive designs. It explains Flexbox usage, compares it with CSS Grid, and details browser support.

How can we make our website responsive using CSS?How can we make our website responsive using CSS?Apr 30, 2025 pm 03:19 PM

The article discusses techniques for creating responsive websites using CSS, including viewport meta tags, flexible grids, fluid media, media queries, and relative units. It also covers using CSS Grid and Flexbox together and recommends CSS framework

What does the CSS box-sizing property do?What does the CSS box-sizing property do?Apr 30, 2025 pm 03:18 PM

The article discusses the CSS box-sizing property, which controls how element dimensions are calculated. It explains values like content-box, border-box, and padding-box, and their impact on layout design and form alignment.

How can we animate using CSS?How can we animate using CSS?Apr 30, 2025 pm 03:17 PM

Article discusses creating animations using CSS, key properties, and combining with JavaScript. Main issue is browser compatibility.

Can we add 3D transformations to our project using CSS?Can we add 3D transformations to our project using CSS?Apr 30, 2025 pm 03:16 PM

Article discusses using CSS for 3D transformations, key properties, browser compatibility, and performance considerations for web projects.(Character count: 159)

How can we add gradients in CSS?How can we add gradients in CSS?Apr 30, 2025 pm 03:15 PM

The article discusses using CSS gradients (linear, radial, repeating) to enhance website visuals, adding depth, focus, and modern aesthetics.

What are pseudo-elements in CSS?What are pseudo-elements in CSS?Apr 30, 2025 pm 03:14 PM

Article discusses pseudo-elements in CSS, their use in enhancing HTML styling, and differences from pseudo-classes. Provides practical examples.

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

Video Face Swap

Video Face Swap

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

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Safe Exam Browser

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.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft