current position:Home>HTML text elements and CSS font processing
HTML text elements and CSS font processing
2021-08-26 19:59:17 【A bowl week】
This is my participation 8 The fourth of the yuegengwen challenge 22 God , Check out the activity details :8 Yuegengwen challenge
Hello Hello everyone , I am a A bowl week , Not the one you think “ A cup of porridge ”, It's a front end that doesn't want to be drunk , If I'm lucky enough to get your favor , I'm very lucky ~
This is a 【 Learn from scratch 】 Chapter 18 of the series -《CSS Font processing and HTML Elements about text in 》
This series of articles starts at nuggets , It is not easy to reprint. Please get permission
Write it at the front
In this article, we will HTML About text elements and CSS Font processing in , Through this article, you can master the following contents :
HTML Provides elements about text
HTML There are two main types of text elements provided in , As follows :
-
Structured elements : It refers to elements with clear meaning and function .
-
Semantic elements : Semantic elements also refer to elements with meaning , The difference is that semantic elements define more words 、 The semantics or style of a line of content .
Structured elements
HTML The structural elements provided are shown in the following table :
Elements | describe |
---|---|
<h1>~<h6> |
Title element ,<h1> Highest level . |
<p> |
Paragraph elements |
<b> |
Bold elements |
<i> |
Tilt elements |
<sup> |
Superscript element |
<sub> |
Subscript element |
<br> |
Line break |
<hr> |
Level |
<article> |
Article container element ( No default style ) |
<section> |
Chapter container elements ( No default style ) |
<nav> |
Navigation container elements |
aside> |
Side description elements |
<header> |
Head area container |
<main> |
Body area container |
<footer> |
Bottom area container |
That's all HTML Structured elements provided in , Now let's look at these elements in HTML Specific effects in :
Now let's see <h1>~<h6>
、<p>
Elements and other elements , The sample code is as follows :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> Text elements </title>
</head>
<body>
<h1> First level title </h1>
<h2> Secondary title </h2>
<h3> Three level title </h3>
<h4> The fourth level title </h4>
<h5> Five level titles </h5>
<p> This is a passage </p>
<b> This is a bold text </b>
<!-- Line break -->
<br>
<i> This is an oblique text </i>
<!-- Split line -->
<hr>
<p>
<sup> Superscript </sup> written words
<sub> Subscript </sub>
</p>
<h6> Six level title </h6>
</body>
</html>
Copy code
The code runs as follows :
Semantic elements
HTML The semantic elements provided in are shown in the following table :
Elements | semantics | According to the effect |
---|---|---|
<strong> |
Bold elements | Bold font effect |
<em> |
Emphasize elements | Font tilt effect |
<blockquote> and <q> |
Reference effect | First line indent effect |
<cite> |
Citation effect | Font tilt effect |
<dfn> |
Define the element | Font tilt effect ( Some browsers have no effect ) |
<address> |
The address element | Font tilt effect |
<del> and <ins> |
Content modification element | Font strikeout effect and underline effect |
That's all HTMl About semantic elements provided in , The specific effect of its elements, let's take a look at its browser effect .
The sample code is as follows :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> Semantic elements </title>
</head>
<body>
<strong> This is the bold element </strong>
<em> Emphasize effect </em>
<blockquote> Reference element </blockquote>
<cite> Citation elements </cite>
<dfn> Define the element </dfn>
<address> The address element </address>
<del> Delete line element </del>
<ins> Underline element </ins>
</body>
</html>
Copy code
The code runs as follows :
HTML Whitespace handling and escape characters in
Blank handling
When the browser runs and parses HTML When the page is , When two or more consecutive spaces are encountered , If you don't deal with spaces , Just show it as a space , This feature is called Empty space collapse .
The sample code is as follows :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> Blank handling </title>
</head>
<body>
<p> This is a paragraph. written words </p>
<p> This is a paragraph. written words </p>
</body>
</html>
Copy code
The code runs as follows :
In the above code , the second <p>
There are two spaces in the element , Better than the first <p>
One more element , But the display effect is the same .
Escape character
stay HTML The characters in <
、>
、"
、'
and &
And so on are special characters , They are HTML A part of grammar itself . If you want to run in the browser HTML The page presents these special characters , Must be used by Escape character To achieve .
literal character | describe | Escape character |
---|---|---|
|
Space | |
< |
Less than no. | < |
> |
More than no. | > |
& |
And no. | & |
" |
quotes | " |
|
Copyright | © |
|
Registered trademark | ® |
|
trademark | ™ |
× |
Multiplication sign | × |
÷ |
devide | ÷ |
The sample code is as follows :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title> Escape character </title>
</head>
<body>
<p>HTML of use <p> To define paragraph elements </p>
</body>
</html>
Copy code
The code runs as follows :
Font style
CSS The operation of font in is mainly to set the font thickness 、 Size, etc .CSS The operation of fonts in is mainly through font
attribute , This attribute can be split into the following attributes :
-
font-family
attribute -
font-size
attribute -
font-weight
attribute -
font-style
attribute
HTTP:
CSS Medium font-family
Property can be set through a list of font names or font family names HTML The font in the page . The live sample code is as follows :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title> HTTP: </title>
<style> #p { font-family: Song style ; } </style>
</head>
<body>
<p> Use the default font p Elements </p>
<p id="p"> Use the specified font p Elements </p>
</body>
</html>
Copy code
The code runs as follows :
font-family
Property can not only set a font name , It can also set multiple font names ( Font family name ), Separated by commas . When setting multiple , The browser will use its font in turn . The sample code is as follows :
p {
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
}
Copy code
font size
CSS Pass through font-size
To set the font size , Its attribute value can be set to a variety of values , The details can be obtained through MDN see , In actual development , Only absolute units px
And relative units rem
、em
.
The sample code is as follows :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title> font size </title>
<style> #p { font-size: 24px; } </style>
</head>
<body>
<p> Default font size </p>
<p id="p"> Specify font size </p>
</body>
</html>
Copy code
The code runs as follows :
Font thickness and tilt
CSS Through font-weight
Property to set the font thickness , The value of this property can be 100~900
It can also be normal
( And 400 Equivalent ) perhaps bold
( And 700 Equivalent ) Two values .
adopt font-style
To set the font tilt , Its attribute value can be italic
perhaps oblique
.
It is worth noting that , You can set the thickness and inclination on the premise that the font includes this font style .
The sample code is as follows :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title> Thickness and inclination </title>
<style> .bold { font-weight: bold; } .italic { font-style: italic; } </style>
</head>
<body>
<p class="bold"> Font bold processing </p>
<p class="italic"> Font tilt processing </p>
</body>
</html>
Copy code
The code runs as follows :
font attribute
CSS Medium font
Attributes can be short for which of the above attributes , Specific grammar can refer to MDN. However, the shorthand attribute is used in actual development , Readability is not very good .
@font-face The rules
@font-face
Rules are used in HTML Embed Fonts , Used in HTML Introduce online fonts into the page . The grammatical rules are as follows :
@font-face {
[ font-family: <family-name>; ] ||
[ src: <src>; ] ||
[ unicode-range: <unicode-range>; ] ||
[ font-variant: <font-variant>; ] ||
[ font-feature-settings: <font-feature-settings>; ] ||
[ font-variation-settings: <font-variation-settings>; ] ||
[ font-stretch: <font-stretch>; ] ||
[ font-weight: <font-weight>; ] ||
[ font-style: <font-style>; ]
}
Copy code
The specific contents of the above grammatical structure are as follows :
-
font-family
: The specified font name will be used forfont
orfont-family
attribute . -
src
: adopturl()
Function to specify the location of the remote font file , Or bylocal()
The function specifies the font on the user's local computer . -
font-variant
: Same asfont-variant
attribute . -
font-stretch
: Same asfont-stretch
attribute . -
font-weight
: Same asfont-weight
attribute . -
font-style
: Same asfont-style
attribute .
The above grammar rules are taken from MDN
The following example code shows font
Property usage :
@font-face {
font-family: 'Varela Round';
font-style: normal;
font-weight: 400;
font-display: swap;
src: url(https://fonts.gstatic.com/s/varelaround/v13/w8gdH283Tvk__Lua32TysjIfp8uP.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
body {
font-family: 'Varela Round', serif
}
Copy code
summary
Notice : In the next article, we will study CSS Text processing in
copyright notice
author[A bowl week],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2021/08/20210826195912276t.html
The sidebar is recommended
- Crazy blessing! Tencent boss's "million JVM learning notes", real topic of Huawei Java interview 2020-2021
- JS JavaScript how to get the subscript of a value in the array
- How to implement injection in vuex source code?
- JQuery operation select (value, setting, selected)
- One line of code teaches you how to advertise on Tanabata Valentine's Day - Animation 3D photo album (music + text) HTML + CSS + JavaScript
- An article disassembles the pyramid architecture behind the gamefi outbreak
- BEM - a front-end CSS naming methodology
- [vue3] encapsulate custom global plug-ins
- Error using swiper plug-in in Vue
- Another ruthless character fell by 40000, which was "more beautiful" than Passat and maiteng, and didn't lose BMW
guess what you like
-
Huang Lei basks in Zhang Yixing's album, and the relationship between teachers and apprentices is no less than that in the past. Netizens envy Huang Lei
-
He was cheated by Wang Xiaofei and Li Chengxuan successively. Is an Yixuan a blessed daughter and not a blessed home?
-
Zhou Shen sang the theme song of the film "summer friends and sunny days" in mainland China. Netizen: endless aftertaste
-
Pink is Wangyuan online! Back to the peak! The new hairstyle is creamy and sassy
-
Front end interview daily 3 + 1 - day 858
-
Spring Webflux tutorial: how to build reactive web applications
-
[golang] walk into go language lesson 24 TCP high-level operation
-
August 23, 2021 Daily: less than three years after its establishment, Google dissolved the health department
-
The female doctor of Southeast University is no less beautiful than the female star. She has been married four times, and her personal experience has been controversial
-
There are many potential safety hazards in Chinese restaurant. The top of the program recording shed collapses, and the artist will fall down if he is careless
Random recommended
- Anti Mafia storm: He Yun's helpless son, Sun Xing, is destined to be caught by his dry son
- Introduction to flex flexible layout in CSS -- learning notes
- CSS learning notes - Flex layout (Ruan Yifeng tutorial summary)
- Today, let's talk about the arrow function of ES6
- Some thoughts on small program development
- Talk about mobile terminal adaptation
- Unwilling to cooperate with Wang Yibo again, Zhao Liying's fans went on a collective strike and made a public apology in less than a day
- JS function scope, closure, let, const
- Zheng Shuang's 30th birthday is deserted. Chen Jia has been sending blessings for ten years. Is it really just forgetting to make friends?
- Unveil the mystery of ascension
- Asynchronous solution async await
- Analysis and expansion of Vue infinite scroll source code
- Compression webpack plugin first screen loading optimization
- Specific usage of vue3 video play plug-in
- "The story of huiyeji" -- people are always greedy, and fairies should be spotless!
- Installing Vue devtool for chrome and Firefox
- Basic usage of JS object
- 1. JavaScript variable promotion mechanism
- Two easy-to-use animation JS that make the page move
- Front end Engineering - scaffold
- Java SQL Server intelligent fixed asset management, back end + front end + mobile end
- Mediator pattern of JavaScript Design Pattern
- Array de duplication problem solution - Nan recognition problem
- New choice for app development: building mobile applications using Vue native
- New gs8 Chengdu auto show announces interior Toyota technology blessing
- Vieira officially terminated his contract and left the team. The national security club sent blessings to him
- Less than 200000 to buy a Ford RV? 2.0T gasoline / diesel power, horizontal bed / longitudinal bed layout can be selected
- How does "heart 4" come to an end? Pinhole was boycotted by the brand, Ma Dong deleted the bad comments, and no one blessed him
- We are fearless in epidemic prevention and control -- pay tribute to the front-line workers of epidemic prevention!
- Front end, netty framework tutorial
- Xiaomi 11 | miui12.5 | android11 solves the problem that the httpcanary certificate cannot be installed
- The wireless charging of SAIC Roewe rx5 plus is so easy to use!
- Upload and preview pictures with JavaScript, and summarize the most complete mybatis core configuration file
- [25] typescript
- CSS transform Complete Guide (Second Edition) flight.archives 007
- Ajax foundation - HTTP foundation of interview essential knowledge
- Cloud lesson | explain in detail how Huawei cloud exclusive load balancing charges
- Decorator pattern of JavaScript Design Pattern
- [JS] 10. Closure application (loop processing)
- Left hand IRR, right hand NPV, master the password of getting rich