Home >Web Front-end >HTML Tutorial >The most comprehensive summary of HTML and CSS knowledge points in history, easy to understand. _html/css_WEB-ITnose

The most comprehensive summary of HTML and CSS knowledge points in history, easy to understand. _html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:56:012196browse

1. Basics of html css
1-1
The relationship between Html and CSS
Learning the basic technologies of web front-end development requires mastering: HTML, CSS, and JavaScript languages. Let’s take a look at what these three technologies are used to achieve:
1. HTML is the carrier of web content. Content is the information that web page creators put on the page for users to browse, and can include text, pictures, videos, etc.
2. CSS style is performance. It's like a coat for a web page. For example, title font, color changes, or adding background images, borders, etc. to the title. All these things used to change the appearance of content are called presentations.
3. JavaScript is used to implement special effects on web pages. For example: the drop-down menu pops up when the mouse slides over it. Or the background color of the table changes when the mouse rolls over it. There is also a rotation of hot news (news pictures). It can be understood that animation and interaction are generally implemented using JavaScript.
1-2
1. HTML tags are not case-sensitive.

and

are the same, but lowercase is recommended because most programmers use lowercase.


1-3
An HTML file has its own fixed structure.

...
...

Code explanation :
1. is called the root tag, and all web page tags are in .
2. The tag is used to define the head of the document, which is a container for all head elements. Header elements include , <script>, <style>, <link>, <meta> and other tags. Header tags will be introduced in detail in the next section. <br> 3. The content between the <body> and </body> tags is the main content of the webpage, such as <h1>, <p>, <a>, <img> and other webpage content tag, the content in the tag here will be displayed in the browser. <br> <br> <br> 1-4 <br> 1. The following tags can be used in the head section: <br> <head> <br> <title>...</title> <br> <meta> <br> ; <link> <br> ; <style>...</style> <br> ; <script>...</script> <br> </head> <br> 2. Code comments not only make it easier for programmers to recall the purpose of previous codes, but also help other programmers quickly understand the functions of your program, making it easier for multiple people to collaborate in developing web page code. <br> Syntax: <br> <!--Comment text--> <br> 3. CSS comment code <br> Just like comments in Html, there are also comment statements in CSS: use /* comment statements */ to indicate (use <!--comment statement--> in Html) <br> <br> <br> 1-5 <br> 1. Semanticization: To put it simply, understand each tag (Under what circumstances can I use this tag to be reasonable?) For example, the title of an article on a web page must use a title tag, and the column names of each column on a web page can also use title tags. <br> 2. The role of semantics <br> 1). Easier to be indexed by search engines. <br> 2). Make it easier for screen readers to read web content. <br> <br> <br> 2. Understanding tags (Part 1) <br> 2-1 <br> If you want to display an article on a web page, you need the <p> tag, and put the paragraphs of the article into the <p> tag. <br> Syntax: <br> <p>Paragraph text</p> <br> <br> <br> 2-2 <br> <hx> tag to create the title of the article. <br> There are 6 title tags in total, h1, h2, h3, h4, h5, and h6 are first-level headings, second-level headings, third-level headings, fourth-level headings, fifth-level headings, and sixth-level headings respectively. And in descending order of importance. <h1> is the highest level. <br> Syntax: <br> <hx>Title text</hx> (x is 1-6) <br> As mentioned before, the title of the article can use the title tag. In addition, the title text of each column on the web page They can also be used in titles <br> <br> <br> 2-3 <br> With paragraphs and titles, now if you want to emphasize certain words in a paragraph, you can use < em> or <strong> tag. <br> But there is a difference in the tone of emphasis: <em> means emphasis, <strong> means stronger emphasis. And in browsers, <em> is expressed in italics by default, and <strong> is expressed in bold. Compared with the two tags, domestic front-end programmers currently prefer to use <strong> to express emphasis <br> <br> <br> 2-4 <br> <em>, <strong>, <span> Difference: <br>1. The <em> and <strong> tags are used to emphasize keywords in a paragraph, and their semantics are emphasis. <br> 2. The <span> tag has no semantics. Its function is to set a separate style, encircle a paragraph, and then use CSS to set the style. <br> <br> <br> 2-5 <br> q tag, short text quote <br> For example, if you want to quote a poem by a certain writer in an article on your web page, this will make your article more outstanding. Then the <q> tag is what you need. <br> Syntax: <br> <q>Quote text</q> <br> 1. Note that the text to be quoted does not need to be quoted in double quotes. The browser will automatically add double quotes to the q tag. <br> 2. Note that the real key point of using the <q> tag here is not its default style of double quotes (in this case, we might as well enter the double quotes on the keyboard ourselves), but its semantics: quoting someone else's words<br> <br> <br> blockquote tag, long text quotation <br> <blockquote> is also used to quote other people’s text. But it is a reference to long text <br> The <q> tag is a reference to short text. For example, the <q> tag is used to quote a sentence. <br> Syntax: <br> <blockquote>Quote text</blockquote> <br> The browser parses the <blockquote> tag in the indentation style <br> <br> <br> 2-6 <br> Line break tag<br/> <br> <br/>The tag is equivalent to the carriage return in a word document. <br> The dividing line tag<hr/> <br> The <hr/> tag is also an empty tag like the <br/> tag, so there is only one start tag and no end tag. <br> The default style of the <hr/> tag in the browser has thicker lines and gray color. Some people may find this style unsightly, but that’s okay. We will learn about these external styles in the future using CSS styles. After the table is created, it can be modified. <br> <br> <br> 2-7 <br> html special characters <br> Space:   (; semicolon is essential) <br> <br> <br> 2-8 <br> address tag , add address information to the web page <br> Syntax: <br> <address>Address information</address> <br> For example: <br> <address>No. 10 Dewai Street, Xicheng District, Beijing</address> ; <br> The style displayed on the browser is italic. If you don’t like italics, of course you can. You can use css styles to modify it in later lessons. The default style of <address> tag <br> <br> <br> 2-9 <br> In websites that introduce language technology, it is inevitable to display some computer professional programming code on the web page. When the code is one line of code, you can use the <code> tag, as in the following example: <br> <code>var i=i 300;</code> <br> Syntax: <br> <code>Code Language</code> <br> Note: Generally, if you want to insert multiple The <code> tag cannot be used for lines of code. If it is multiple lines of code, the <pre class="brush:php;toolbar:false"> tag can be used. <br> <br> <br> <pre class="brush:php;toolbar:false"> The main function of the tag: preformatted text. Text enclosed in a pre element usually preserves whitespace and newlines. If you use the previous method, you need to enter the <br> sign for the carriage return and the   for the space. <br> Note: The <pre class="brush:php;toolbar:false"> tag is not only used to display the source code of the computer. You can use it when you need to pre-display the format in the web page. However, a common application of the <pre class="brush:php;toolbar:false"> tag is to Display the computer's source code. <br> <br> <br> 3. Understanding tags (Part 2) <br> 3-1 <br> 1. Unordered list <br> ul-li is a list of information in no order. <br> Syntax: <br> <ul> <br> <li>Message</li> <br> <li>Message</li> <br> ...... <br> </ul> <br> Example: <br> <ul> <br> <li>Wonderful Boy</li> <br> <li>Beauty suddenly appears</li> <br> < ;li>Soul-touching melody</li> <br> </ul> <br> The default style of ul-li displayed on the web page is generally: each li has a dot in front of it <br> <br> <br> 2. Ordered list <br> Syntax: <br> <ol> <br> <li>Information</li> <br> <li>Information</li> <br> ...... <br> </ol> <br> Example: <br> The following is a popular course download ranking: <br> <ol> <br> <li>Front-end development interview experience Method</li> <br> <li>Learning html from scratch</li> <br> <li>JavaScript Complete Guide</li> <br> </ol> <br> <ol>在网页中显示的默认样式一般为:每项<li>前都自带一个序号,序号默认从1开 <br> <br> <br> 3-2 <br> <div>容器标签 <br> 在网页制作过程过中,可以把一些独立的逻辑部分划分出来,放在一个<div>标签中,这个<div>标签的作用就相当于一个容器。 <br> 语法: <br> <div>…</div> <br> Determine the logical part: <br> What is the logical part? It is a set of interrelated elements on the page. For example, an independent column section in a web page is a typical logical part. As shown in the figure below: The part marked with a red border in the figure is a logical part, and you can use the <div> tag as a container <br> Note: <div> is a block-level element, that is, the browser Usually a line break is placed before and after the div element. <br> <br> <br> 3-3 <br> Five elements to create a table: <br> table, tbody, tr, th, td <br> 1. <table>…</table>: The entire table starts with the <table> tag and ends with the </table> tag. <br> 2. <tbody>…</tbody>: When there is a lot of table content, the table will be downloaded and displayed a little bit, but if the <tbody> tag is added, the table will have to wait until all the table contents are downloaded. will be displayed. Such as the code in the code editor on the right. (This tag is basically not used much anymore) <br> 3. <tr>...</tr>: A row of the table, so there are several pairs of tr and the table has several rows. <br> 4. <td>…</td>: A cell in a table. One row contains several pairs of <td>...<td/>, indicating how many columns there are in one row. <br> 5. <th>…</th>: A cell at the head of the table, table header. <br> 6. The number of columns in the table depends on the number of data cells in a row. <br> <br> <br> The table still needs to add some tags for optimization. You can add a title and summary <br> <table summary="This table records inventory records from 2012 to 2013. The records include U disk and headphone inventory. Quantity"> <br> <caption>Inventory record from 2012 to 2013</caption> <br> <br> <br> 3-4 <br> 1. Use the <a> tag to link to other A page <br> uses the <a> tag to implement a hyperlink. It can be said to be ubiquitous in web page production. As long as there is a link, there will be this tag. <br> Syntax: <br> <a href="Destination URL">Text displayed in the link</a> <br> For example: <br> <a href = "http://www.imooc. com">click here!</a> <br> The above example is to click the click here! text, and the webpage links to the webpage http://www.imooc.com. < img> tag to insert images. <br> Syntax: <br> <img src="image address" alt="replacement text when download fails" title = "prompt text"> <br> Example: <br> <img src = "myimage .gif" alt = "My Image" title = "My Image" /> <br> Explanation: <br> 1. src: identifies the location of the image; <br> 2. alt: specifies the descriptive text of the image, when When the image is not visible (when the download is unsuccessful), the text specified by this attribute can be seen; <br> 3. title: Provides a description of the image when the image is visible (the text displayed when the mouse rolls over the image); <br> 4. The image can be an image file in GIF, PNG, or JPEG format. <br> <br> <br> 4. Form tags (interacting with users) <br> 4-1 <br> The form can transmit the data entered by the viewer to the server, so that the server-side program can process the form transmitted data. <br> Syntax: <br> <form method="Transmission method" action="Server file"> <br> Explanation: <br> 1.<form>: <form> tags appear in pairs , starting with <form> and ending with </form>. <br> 2. action: The place where the data entered by the viewer is sent, such as a PHP page (save.php). <br> 3.method: method of data transmission (get/post). <br> <br> <br> 4-2 <br> <input>Input box<br> Text input box, password input box<br> When the user wants to type letters, numbers, etc. in the form, they will Use text input box. The text box can also be converted into a password input box. <br> Syntax: <br> <form> <br> <input type="text/password" name="name" value="text" /> <br> </form> <br> 1 , type: <br> When type="text", the input box is a text input box; <br> When type="password", the input box is a password input box. <br> 2. name: Name the text box for use by the background programs ASP and PHP. <br> 3. value: Set the default value for the text input box. (Generally used as a prompt) <br> <br> <br> 4-3 <br> Text field, supports multi-line text input <br> When the user needs to enter a large piece of text in the form, text input is needed domain. <br> Syntax: <br><textarea rows="Number of rows" cols="Number of columns">Text</textarea> <br> 1. <textarea> tags appear in pairs, starting with <textarea> and ending with </ textarea>End. <br> 2. cols: The number of columns in a multi-line input field. <br> 3. rows: The number of rows in a multi-line input field. <br> <br> <br> 4-4 <br> Radio button, checkbox <br> Syntax: <br> <input type="radio/checkbox" value="value" name="name" checked="checked"/> <br> 1. type: <br> When type="radio", the control is a radio button<br> When type="checkbox", the control is a check box<br> 2. value: the value of submitting data to the server (used by background program PHP) <br> 3. name: name the control for use by background programs ASP and PHP <br> 4. checked: when set checked="checked" , this option is selected by default <br> Note: The name values ​​of radio buttons in the same group must be consistent, so that the radio buttons in the same group can function as radio selections. <br> <br> <br> 4-5 <br> Drop-down list box, save space <br> Drop-down list is also often used in web pages, it can effectively save web page space. You can select both single and multiple selections. <br> Syntax: <option value="Submit value">Option</option> <br> The submitted value is the value submitted to the server, and the option is the displayed value. <br> <form action="save.php" method="post" > <br> <br> <label>Hobbies:</label> <br> <br> <select> <br> <br> <option value="Reading">Reading</option> <br> <br> <option value="Travel" selected="selected">Travel</option> <br> <br> <option value="Sports">Sports</option> <br> <br> <option value="Shopping">Shopping</option> <br> <br> </select> ; <br> <br> <br> </form> <br> <br> <br> 4-6 <br> Use the drop-down list box for multiple selections <br> The drop-down list can also perform multiple selection operations. Setting the multiple="multiple" attribute in the <select> tag, <br> can realize the multi-select function. When making multiple selections, press the Ctrl key and click at the same time to select multiple options. <br> The following code: <br> <form action="save.php" method="post" > <br> <br> <label>Hobbies:</label> <br> <br> < ;select multiple="multiple"> <br> <br> <br> ; <option value="Read a book">Read a book</option> <br> <br> <br> ">Travel</option> <br> <br> <br>  <option value="Sports">Sports</option> <br> <br> <br> ">Shopping</option> <br> <br> </select> <br> <br> <br> </form> <br> <br> <br> 4-7 <br> in There are two kinds of buttons that can be used in the form, namely: submit button and reset. <br> 1. Submit button: When users need to submit form information to the server, they need to use the submit button. <br> Syntax: <br> <input type="submit" value="submit"> <br> type: Only when the type value is set to submit, the button can submit <br> value: displayed on the button The text of <br> <br> <br> 2. Reset button, reset form information <br> When the user needs to reset the form information to the initial state, for example, after the user enters "user name", they find that there is If there is an error, you can use the reset button to restore the input box to its initial state. Just set type to "reset". <br> Syntax: <br> <input type="reset" value="Reset"> <br> type: The button has a reset effect only when the type value is set to reset <br> value: button The text displayed on <br> <br> <br> 5. css style <br> 5-1 <br> Understanding css style <br> CSS stands for "Cascading Style Sheets", which is mainly used It is used to define the display style of HTML content in the browser, such as text size, color, font boldness, etc. <br> The following code is as follows: <br> p{ <br> font-size:12px; <br> color:red; <br> font-weight:bold; <br> } <br>One benefit of using CSS styles is that by defining a certain style, text in different web page locations can have a unified font, font size, or color. <br> <br> <br> 5-2 <br> CSS code syntax <br> css style consists of selectors and declarations, and declarations consist of attributes and values ​​<br> Selector {property: value} <br> p{color:red;} <br> Selector: Also known as selector, it specifies the elements in the web page to which style rules should be applied. For example, in this example, the text of all paragraphs (p) in the web page will turn blue. Other elements (such as ol) will not be affected. <br> Declaration: What is enclosed in English curly brackets "{}" is the declaration, and the attributes and values ​​are separated by English colons ":". When there are multiple statements, they can be separated by English semicolons ";", as shown below: <br> p{font-size:12px;color:red;} <br> <br> <br> 5-3 <br> From the perspective of the form of CSS style code insertion, it can be basically divided into the following three types: <br> Inline, embedded and external <br> 1. Inline css style <br> is to insert css code Write directly in the existing HTML tag, such as the following code: <br> <p style="color:red">The text here is red. </p> <br> The css style code should be written in double quotes. If there are multiple css style code settings, they can be written together and separated by semicolons. The following code: <br> <p style="color:red;font-size:12px">The text here is red. </p> <br> <br> <br> 2. Embedded css style, <br> means you can write the css style code in the <style type="text/css"></style> tag between. For example, the following code sets the text in the three <span> tags to red: <br> <style type="text/css"> <br> span{ <br> color:red; <br> } <br> </style> <br> Embedded css styles must be written between <style></style>, and generally embedded css styles are written between <head></head> between. <br> <br> <br> 3. External css style <br> is written in a separate file <br> External css style (also called external style) is to write the css code in a separate external In the file, this css style file has the extension ".css", and the <link> tag is used within the <head> (not within the <style> tag) to link the css style file to the HTML file, as shown below Code: <br> <link href="base.css" rel="stylesheet" type="text/css" /> <br> Note: <br> 1. The css style file name starts with meaningful English letters Name it, such as main.css. <br> 2. rel="stylesheet" type="text/css" is a fixed writing method and cannot be modified. <br> 3. The <link> tag position is generally written within the <head> tag. <br> <br> <br> Six, CSS selector <br> Each css style definition consists of two parts, the form is as follows: <br> selector { <br> style; <br> } <br> in { The part before } is the "selector", and the "selector" specifies the object of the "style" in {}, that is, which elements in the web page the "style" acts on <br> <br> <br> 6- 1. Tag selector <br> Tag selector is actually a tag in html code. Such as <html>, <body>, <h1>, <p>, <img> in the code editor on the right. For example, the following code: <br> p{font-size:12px;line-height:1.6em;} <br> The function of the above css style code is to set the font size of 12px for the p tag and the line spacing to 1.6em. <br> <br> <br> 6-2, Class selector <br> Class selector is the most commonly used in CSS style coding, such as the code in the code editor on the right: It can be implemented as "timid as The fonts of "Rat" and "Courage" are set to red. <br> Syntax: <br> .Class selector name{css style code;} <br> Note: <br> 1. Begin with an English dot <br> 2. The name of the class selector can be named arbitrarily (but do not Chinese) <br> How to use: <br> Step 1: Use appropriate tags to mark the content to be modified, as follows: <br> <span>As timid as a mouse</span> <br> Chapter Step 2: Use class="class selector name" to set a class for the label, as follows: <br> <span class="stress">Scared as a Mouse</span> <br> Step 3: Setting The class selector css style is as follows: <br> .stress{color:red;}/*Add an English dot in front of the class*/ <br> <br> <br> 6-3, ID selector <br> In many ways, ID selectors are similar to class selectors, but there are some important differences: <br> 1. Set id="ID name" for the tag instead of class="class name". <br> 2. The ID selector is preceded by a pound sign (#) instead of an English dot (.). <br> <br> <br> 6-4, the difference between class and ID selector <br> Similarity: can be applied to any element <br> Difference: <br>1. The ID selector can only be used once in the document. Unlike class selectors, ID selectors can only be used once, and only once, in an HTML document. Class selectors can be used multiple times. <br> The following code is correct: <br> <p>When I was in third grade, I was a little girl who was <span class="stress">timid as a mouse</span> and never dared to go to class. When I answer the questions raised by the teacher, I am afraid that the teacher will criticize me if I answer the wrong question. I never had the<span class="stress">courage</span> to answer the teacher's questions. </p> <br> And the following code is wrong: <br> <p>In the third grade, I was still a <span id="stress">timid little kid</span> As a girl, I never dared to answer the teacher’s questions in class, for fear that the teacher would criticize me if I answered wrongly. I never had the<span id="stress">courage</span> to answer the teacher's questions. </p> <br> 2. You can use the class selector word list method to set multiple styles for an element at the same time. We can set multiple styles for an element at the same time, but this can only be achieved using class selectors, not ID selectors (ID word lists cannot be used). <br> The code below is correct (see the code editor on the right for the complete code) <br> .stress{ <br> color:red; <br> } <br> .bigsize{ <br> font-size:25px ; <br> } <br> <p>In the third grade of<span class="stress bigsize"></span>In the next semester, our class will have an open class...</p> ; <br> The function of the above code is to set the text color of the three words "Third Grade" to red and the font size to 25px <br> <br> <br> The following code is incorrect (see the code editor on the right for the complete code) device) <br> #stressid{ <br> color:red; <br> } <br> #bigsizeid{ <br> font-size:25px; <br> } <br> <p>Arrived<span id ="stressid bigsizeid">Third grade</span>In the next semester, our class will have an open class...</p> <br> The above code cannot be implemented as the three characters "Third grade" Set the text color to red and the font size to 25px. <br> <br> <br> 6-5, sub-selector <br> There is also a more useful selector sub-selector, namely the greater than symbol (>), which is used to select the child elements of the specified label element. For example, the following code: <br> .food>li{border:1px solid red;} <br> This line of code will add a solid red border to the sub-element li under the class name food. <br> <br> <br> 6-6, Contains (descendant) selector <br> Contains a selector, that is, adding spaces, which is used to select descendant elements under the specified label element. Such as the code in the code editor on the right: <br> .first span{color:red;} <br> Please note the difference between this selector and the child selector <br> 1. The child selector (child selector) is only Refers to its direct descendants, or you can understand it as the first generation descendants that act on child elements <br> 2. The descendant selector acts on all child descendant elements. Descendant selectors select with spaces, while child selectors select with ">". <br> Summary: > Acts on the first generation descendants of the element, and spaces act on all descendants of the element. <br> <br> <br> 6-7, universal selector <br> The universal selector is the most powerful selector. It is specified with a (*) sign. Its function is to match any tag element in html. , use the following code to set the font color of any tag element in HTML to red: <br> * {color:red;} <br> <br> <br> 6-8, the pseudo-class selector <br> is more interesting is a pseudo-class selector, why is it called a pseudo-class selector? It allows setting styles for tags that do not exist in html. For example, we can set the font color for the mouse-over state of a tag element in html: <br> a: hover{color:red;} <br> This line of code will cause the font color of "TINY AS A MOUSE" in the text content wrapped by the <a></a> tag to turn red when the mouse rolls over. <br> <br> <br> 6-9, grouping selector <br> When you want to set the same style for multiple label elements in html, you can use the grouping selector (,). The following code is the code on the right The h1 and span tags in the editor also set the font color to red: <br> h1,span{color:red;} <br> It is equivalent to the following two lines of code: <br> h1{color:red;} <br> span{color:red;} <br> <br> <br> 7. CSS inheritance, cascading and particularity. <br> 7-1 <br> Some CSS styles are inherited, so what is inheritance? Inheritance is a rule that allows styles to be applied not only to a specific html tag element, but also to its descendants. For example, the following code: If a certain color is applied to the p tag, this color setting applies not only to the p tag, but also to all sub-element text in the p tag, where the sub-element is the span tag. <br> But note that some css styles are not inherited. Such as border:1px solid red; <br> <br> <br> 7-2 <br>Determine which css style to use based on the weight <br> The browser determines which css style to use based on the weight. The css style with the higher weight is used. <br> The following are the weight rules: <br> The weight of the label is 1, the weight of the class selector is 10, and the weight of the ID selector is up to 100. For example, the following code: <br> p{color:red;} /*The weight is 1*/ <br> p span{color:green;} /*The weight is 1 1=2*/ <br> .warning {color:white;} /*The weight is 10*/ <br> p span.warning{color:purple;} /*The weight is 1 1 10=12*/ <br> #footer .note p{color: yellow;} /*The weight is 100 10 1=111*/ <br> Note: There is another weight that is special - inheritance also has a weight but it is very low. Some literature suggests that it is only 0.1, so it can be understood as inheritance. has the lowest weight <br> <br> <br> 7-3, cascading <br> Let’s think about a problem: If there can be multiple css styles for the same element in an html file and these multiple css styles have What to do if the weight values ​​are the same? Well, the cascading in this section helps you solve this problem. <br> Cascading means that multiple css styles can exist for the same element in an html file. When styles with the same weight exist, it will be determined based on the order of these css styles. The last css style will be applied. . <br> Such as the following code: <br> p{color:red;} <br> p{color:green;} <br> <p class="first">In the third grade, I was still a <span> ;A little girl who is as timid as a mouse</span>. </p> <br> Finally, the text in p will be set to green. This cascading is easy to understand. It is understood that the later style will overwrite the previous style. <br> So the previous CSS style priority is not difficult to understand: <br> Inline style sheet (inside the tag) > Embedded style sheet (in the current file) > External style sheet (in the external file). <br> <br> <br> 7-4, Importance <br> Importance <br> When we are doing web page code, there are some special situations where we need to set the highest weight for certain styles. What should we do? At this time we can use !important to solve it. <br> The following code: <br> p{color:red!important;} <br> p{color:green;} <br> <p class="first">In the third grade, I was still a< span>A little girl who is as timid as a mouse</span>. </p> <br> At this time, the text in the p paragraph will be displayed in red. <br> Note: !important should be written in front of the semicolon <br> <br> <br> 8. CSS formatting and typesetting <br> 8-1 <br> Text typesetting <br> 1. Text typesetting - font <br> We can use css styles to set style attributes such as font, font size, color, etc. for the text in the web page. Let's take a look at an example. The following code implements: setting the font for the text in the web page to Song Dynasty. <br> body{font-family:"宋体";} <br> Be careful not to set uncommon fonts here, because if the font you set is not installed on the user's local computer, the browser's default font 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.) <br> 2. Text layout - font size, color <br> You can use the following code to set the text in the web page The font size is 12 pixels, and the font color is set to #666 (gray): <br> body{font-size:12px;color:#666} <br> 3. Text layout--bold <br> 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. <br> p span{font-weight:bold;} <br> 4. Text layout - italic <br> The following code can display text in italic style in the browser: <br> p a{font-style:italic ;} <br> <p>In the third grade, I was a little girl who was <a>timid as a mouse</a>. </p> <br> 5. Text layout - underline <br> In some cases, you want to set the text to underline style, which can visually emphasize the text. You can use the following code to achieve this: <br> p a{text -decoration:underline;} <br> <p>In the third grade, I was a little girl who was <a>timid as a mouse</a>. </p> <br> <br> <br> Strikethrough is often seen on e-commerce websites. <br> p a{text-decoration:line-through;} <br> <br> <br> 8-2 <br> Paragraph formatting <br> 1. Paragraph formatting - indentation <br> Paragraphs in Chinese text I used to leave two spaces blank for text. This special style can be implemented with the following code: <br> p{text-indent:2em;} <br> Note: 2em means twice the size of the text. <br> <br> <br> 2. Paragraph typesetting - line spacing <br> In this section we will learn about another line spacing attribute (line-height) that plays an important role in paragraph typesetting. The following code implements the setting Paragraph line spacing is 1.5x. <br> p{line-height:1.5em;} <br> <br> <br> 3. Paragraph layout--word spacing, letter spacing <br> Text spacing and letter spacing settings: <br>If you want to set text spacing or letter spacing in web page layout, you can use letter-spacing to achieve it, such as the following code: <br> h1{ <br> letter-spacing:50px; <br> } <br> ... <br> <h1>The Great Gatsby</h1> <br> Note: When this style is used in English words, it sets the spacing between letters. <br> Word spacing settings: <br> What if I want to set the spacing between English words? This can be achieved using word-spacing. The following code: <br> h1{ <br> word-spacing:50px; <br> } <br> ... <br> <h1>welcome to imooc!</h1> <br> <br> <br> 9. CSS box model <br> 9-1 <br> Element classification <br> Before explaining CSS layout, we need to know some knowledge in advance. In CSS, label elements in html are generally divided into three different types Types of: block elements, inline elements, and inline block elements. <br> Commonly used block elements are: <br> <div>, <p>, <h1>...<h6>, <ol>, <ul>, <dl>, <table>, <address>, <blockquote>, <form> <br> Commonly used inline elements are: <br> <a>, <span>, <br>, <i> ;, <em>, <strong>, <label>, <q>, <var>, <cite>, <code> <br> Commonly used inline block elements are: <br> <img>, <input> <br> <br> <br> 9-2 <br> Element classification--block-level elements <br> What are block-level elements? In HTML, <div>, <p>, <h1>, <form>, <ul> and <li> are block-level elements. Setting display:block displays the element as a block-level element. The following code converts the inline element a into a block element. The a element from the page has the characteristics of a block element. <br> a{display:block;} <br> Features of block-level elements: <br> 1. Each block-level element starts on a new line, and subsequent elements also start on a new line. (It’s really overbearing, a block-level element occupies one row) <br> 2. The height, width, line height, and top and bottom margins of the element can be set. <br> 3. When not set, the width of an element is 100% of its parent container (the same as the width of the parent element), unless a width is set. <br> <br> <br> 9-3 <br> Element classification--inline elements <br> In html, <span>, <a>, <label>, <input>, < img>, <strong> and <em> are typical inline elements. Of course, block elements can also be set to inline elements through the code display:inline. <br> Characteristics of inline elements: <br> 1. On the same line as other elements; <br> 2. The height, width, line height, and top and bottom margins of the element cannot be set; <br> 3. The width of the element It is the width of the text or image it contains and cannot be changed. <br> <br> <br> 9-4 <br> Element classification--inline block elements <br> Inline-block elements (inline-block) have the characteristics of both inline elements and block elements. The code display:inline-block sets the element to an inline block element. (New in css2.1), <img> and <input> tags are such inline block tags. <br> Features of the inline-block element: <br> 1. It is on the same line as other elements; <br> 2. The height, width, line height, top and bottom margins of the element can be set. <br> <br> <br> 9-5 <br> Box model - border (1) <br> The border of the box model is the line surrounding the content and filler. You can set the thickness and style of this line and color (three attributes of the border). <br> For example, the following code is used for div to set a border with a border thickness of 2px, a solid style, and a red color: <br> div{ <br> border:2px solid red; <br> } <br> The above is the border The abbreviated form of the code can be written separately: <br> div{ <br> border-width:2px; <br> border-style:solid; <br> border-color:red; <br> } <br> Note: <br> 1. Border-style (border style) common styles are: <br> dashed (dashed line) | dotted (dotted line) | solid (solid line). <br> <br> <br> 2. The color in border-color (border color) can be set to hexadecimal color, such as: <br> border-color:#888;//Don’t forget the hash sign in front . <br> <br> <br> 9-6 <br> Box model--border (2) <br> Now there is a problem. If you want to set a lower border for the p tag separately, but do not set a border on the other three sides. What about the style? The css style allows you to set the style for the border in only one direction: <br> div{border-bottom:1px solid red;} <br> You can also use the following code to set the top, right, and left borders on the other three sides: <br> border-top:1px solid red; <br> border-right:1px solid red; <br>border-left:1px solid red; <br> <br> <br> 9-7 <br> Box Model - Border <br> The distance between an element and other elements can be set using margin. The boundaries can also be divided into upper, right, lower and left. The following code: <br> div{margin:20px 10px 15px 30px;} <br> can also be written separately: <br> div{ <br> margin-top:20px; <br> margin-right:10px; <br> margin-bottom:15px; <br> margin-left:30px; <br> } <br> If the top, bottom, left and right borders are both 10px; you can write like this: <br> div{ margin:10px;} <br> If the top and bottom The border is the same 10px, and the left and right are the same 20px. You can write it like this: <br> div{ margin:10px 20px;} <br> To summarize: the difference between padding and margin, padding is inside the border, and margin is outside the border. <br> <br> <br> 9-8 <br> Box model - padding <br> The distance between the element content and the border can be set, which is called padding. Filling can also be divided into top, right, bottom and left. The following code: <br> div{padding:20px 10px15px 30px;} <br> Don’t mix up the order. You can write the above code separately: <br> div{ <br> padding-top:20px; <br> padding-right:10px; <br> padding-bottom:15px; <br> padding-left:30px; <br> } <br> If the top, right, bottom, and left padding are all 10px; you can write like this <br> div{padding:10px;} <br> If the top and bottom padding are the same 10px, and the left and right padding are the same 20px, you can write like this: <br> div{padding:10px 20px;} <br> <br> <br> 9-9 <br> Box model code abbreviation <br> Remember when talking about the box model, margins (margin), padding ( padding) and border (border) settings. The margins in the four directions of top, bottom, left, and right are set in a clockwise direction: top, right, bottom, left. Examples of specific applications in margin and padding are as follows: <br> margin:10px 15px 12px 14px;/*The top is set to 10px, the right is set to 15px, the bottom is set to 12px, and the left is set to 14px*/ <br> Usually there are the following three An abbreviation method: <br> 1. If the values ​​of top, right, bottom and left are the same, as in the following code: <br> margin:10px 10px 10px 10px; <br> can be abbreviated as: <br> margin:10px; <br> 2. If the values ​​of top and bottom are the same, and the values ​​of left and right are the same, as in the following code: <br> margin:10px 20px 10px 20px; <br> can be abbreviated as: <br> margin:10px 20px; <br> 3. If the values ​​of left and right are the same, as in the following code: <br> margin:10px 20px 30px 20px; <br> can be abbreviated to: <br> margin:10px 20px 30px; <br> Note: abbreviation for padding and border The method is the same as margin. <br> <br> <br> 9-10 <br> Color value abbreviation <br> The css style about color can also be abbreviated. When the color you set is a hexadecimal color value, if each two-digit The values ​​are the same and can be abbreviated in half. <br> Example 1: <br> p{color:#000000;} <br> can be abbreviated to: <br> p{color: #000;} <br> Example 2: <br> p{color: #336699 ;} <br> can be abbreviated as: <br> p{color: #369;} <br> <br> <br> <br> <br> 10. CSS layout model <br> 10-1 <br> css Layout model <br> Now that we understand the basic concepts and box model types of the CSS box model, we can delve into the basic model of web page layout. The layout model, like the box model, is the most basic and core concept of CSS. But the layout model is based on the box model and is different from what we often call CSS layout styles or CSS layout templates. If the layout model is the foundation, then the CSS layout template is the end, the external expression. <br> CSS contains 3 basic layout models, summarized in English as: Flow, Layer and Float. <br> In web pages, elements have three layout models: <br> 1. Flow model (Flow) <br> 2. Float model (Float) <br> 3. Layer model (Layer) <br> <br> <br> 10-2 <br> Flow model (1) <br> Flow: top-down. <br> Let’s talk about the flow model first. Flow is the default web page layout mode. That is to say, the HTML web elements of the web page in the default state distribute the web page content according to the flow model. <br> The fluid layout model has two typical characteristics: <br> <br> <br> First, block elements will be vertically extended in order from top to bottom within the containing element, because in By default, the width of block elements is 100%. In fact, block elements all occupy positions in the form of rows. For example, the width of the three block element tags (div, h1, p) in the code editor on the right is displayed as 100%. <br> <br> <br> Second point, under the flow model, inline elements will be displayed horizontally from left to right within the containing element. (Inline elements are not as domineering as block elements and occupy a line alone) <br> The inline element tags a, span, em, and strong in the code editor on the right are all inline elements. <br> <br> <br> 10-3 <br> Floating model <br> 块状元素这么霸道都是独占一行,如果现在我们想让两个块状元素并排显示,怎么办呢?不要着急,设置元素浮动就可以实现这一愿望。任何元素在默认情况下是不能浮动的,但可以用CSS定义为浮动,如div、p、table、img等元素都可以被定义为浮动。如下代码可以实现两个div元素一行显示。 <br> div{ <br>     width:200px; <br>     height:200px; <br>     border:2px red solid; <br>     float:left; <br> } <br> <div id="div1"></div> <br> <div id="div2"></div> <br> <br> <br> 注意:设置浮动的同时一定要先设置块状元素的宽度,且需要浮动的几个元素宽度加起来一定要小于容器元素的宽度。 <br> <br> <br> 10-4 <br> 什么是层模型? <br> 什么是层布局模型?层布局模型就像是图像软件PhotoShop中非常流行的图层编辑功能一样,每个图层能够精确定位操作,但在网页设计领域,由于网页大小的活动性,层布局没能受到热捧。但是在网页上局部使用层布局还是有其方便之处的。下面我们来学习一下html中的层布局。 <br> 如何让html元素在网页中精确定位,就像图像软件PhotoShop中的图层一样可以对每个图层能够精确定位操作。CSS定义了一组定位(positioning)属性来支持层布局模型。 <br> 层模型有三种形式: <br> 1、绝对定位(position: absolute) <br> 2、相对定位(position: relative) <br> 3、固定定位(position: fixed) <br> <br> <br> 1,层模型--绝对定位(相对于父类) <br> 如果想为元素设置层模型中的绝对定位,需要设置position:absolute(表示绝对定位),这条语句的作用将元素从文档流中拖出来,然后使用left、right、top、bottom属性相对于其最接近的一个具有定位属性的父包含块进行绝对定位。如果不存在这样的包含块,则相对于body元素,即相对于浏览器窗口。 <br> 如下面代码可以实现div元素相对于浏览器窗口向右移动100px,向下移动50px。 <br> div{ <br>     width:200px; <br>     height:200px; <br>     border:2px red solid; <br>     position:absolute; <br>     left:100px; <br>     top:50px; <br> } <br> <div id="div1"></div> <br> <br> <br> 2,层模型--相对定位(相对于以前) <br> 如果想为元素设置层模型中的相对定位,需要设置position:relative(表示相对定位),它通过left、right、top、bottom属性确定元素在正常文档流中的偏移位置。相对定位完成的过程是首先按static(float)方式生成一个元素(并且元素像层一样浮动了起来),然后相对于以前的位置移动,移动的方向和幅度由left、right、top、bottom属性确定,偏移前的位置保留不动。 <br> 如下代码实现相对于以前位置向下移动50px,向右移动100px; <br> #div1{ <br>     width:200px; <br>     height:200px; <br>     border:2px red solid; <br>     position:relative; <br>     left:100px; <br>     top:50px; <br> } <br> <div id="div1"></div> <br> <br> <br> 3. Layer model - fixed positioning (relative to the web page window) <br> Fixed a certain coordinate. <br> Fixed: Indicates fixed positioning, similar to the absolute positioning type, but its relative movement coordinates are the view (web page window within the screen) itself. Since the view itself is fixed, it will not change as the scroll bar of the browser window scrolls, unless you move the screen position of the browser window on the screen, or change the display size of the browser window, so fixedly positioned elements will always be in A certain position of the view within the browser window that will not be affected by the flow of the document. This has the same function as the background-attachment:fixed? attribute. The following code can move 100px to the right and 50px down relative to the browser view. And the position remains fixed when dragging the scroll bar. <br> #div1{ <br> width:200px; <br> height:200px; <br> border:2px red solid; <br> position:fixed; <br> left:100px; <br> top:50px; <br> } <br> <br> <br> 10-5 <br> Relative and Absolute combined <br> Friends have learned the relative positioning method in section 12-6: use position:absolute to achieve the setting After positioning an element relative to the browser (body), have you ever thought about whether it can be positioned relative to other elements? The answer is yes, of course. Use position:relative to help, but you must comply with the following specifications: <br> 1. The reference-positioned element must be the predecessor element of the relatively positioned element: <br> <div id="box1"><!--Reference Positioned element--> <br> <div id="box2">Positioned relative to the reference element</div><!--Relatively positioned element--> <br> </div> <br> From the above code, we can see that box1 is the parent element of box2 (the parent element is of course also the predecessor element). <br> 2. Position:relative; <br> #box1{ <br> width:200px; <br> height:200px; <br> position:relative; <br> } <br> 3 , add position:absolute to the positioning element, and then you can use top, bottom, left, and right for offset positioning. <br> #box2{ <br> position:absolute; <br> top:20px; <br> left:30px; <br> } <br> In this way, box2 can be positioned relative to the parent element box1 (note the reference here It doesn’t need to be a browser, but can be set freely). </p></div><div class="nphpQianMsg"><div class="clear"></div></div><div class="nphpQianSheng"><span>Statement:</span><div>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</div></div></div><div class="nphpSytBox"><span>Previous article:<a class="dBlack" title="After submitting the form using submit method in html, how to get the value out on another page_html/css_WEB-ITnose" href="https://m.php.cn/faq/276328.html">After submitting the form using submit method in html, how to get the value out on another page_html/css_WEB-ITnose</a></span><span>Next article:<a class="dBlack" title="After submitting the form using submit method in html, how to get the value out on another page_html/css_WEB-ITnose" href="https://m.php.cn/faq/276330.html">After submitting the form using submit method in html, how to get the value out on another page_html/css_WEB-ITnose</a></span></div><div class="nphpSytBox2"><div class="nphpZbktTitle"><h2>Related articles</h2><em><a href="https://m.php.cn/article.html" class="bBlack"><i>See more</i><b></b></a></em><div class="clear"></div></div><ins class="adsbygoogle" style="display:block" data-ad-format="fluid" data-ad-layout-key="-6t+ed+2i-1n-4w" data-ad-client="ca-pub-5902227090019525" data-ad-slot="8966999616"></ins><script> (adsbygoogle = window.adsbygoogle || []).push({}); </script><ul class="nphpXgwzList"><li><b></b><a href="https://m.php.cn/faq/348757.html" title="Summary of Html knowledge" class="aBlack">Summary of Html knowledge</a><div class="clear"></div></li><li><b></b><a href="https://m.php.cn/faq/348804.html" title="How to learn HTML quickly" class="aBlack">How to learn HTML quickly</a><div class="clear"></div></li><li><b></b><a href="https://m.php.cn/faq/348873.html" title="The difference between html xhtml xml" class="aBlack">The difference between html xhtml xml</a><div class="clear"></div></li><li><b></b><a href="https://m.php.cn/faq/348884.html" title="The difference between src and href attributes" class="aBlack">The difference between src and href attributes</a><div class="clear"></div></li><li><b></b><a href="https://m.php.cn/faq/348902.html" title="About HTML5 and CSS replacement use" class="aBlack">About HTML5 and CSS replacement use</a><div class="clear"></div></li></ul></div></div><ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5902227090019525" data-ad-slot="5027754603"></ins><script> (adsbygoogle = window.adsbygoogle || []).push({}); </script><footer><div class="footer"><div class="footertop"><img src="/static/imghwm/logo.png" alt=""><p>Public welfare online PHP training,Help PHP learners grow quickly!</p></div><div class="footermid"><a href="https://m.php.cn/about/us.html">About us</a><a href="https://m.php.cn/about/disclaimer.html">Disclaimer</a><a href="https://m.php.cn/update/article_0_1.html">Sitemap</a></div><div class="footerbottom"><p> © php.cn All rights reserved </p></div></div></footer><script>isLogin = 0;</script><script type="text/javascript" src="/static/layui/layui.js"></script><script type="text/javascript" src="/static/js/global.js?4.9.47"></script></div><script src="https://vdse.bdstatic.com//search-video.v1.min.js"></script><link rel='stylesheet' id='_main-css' href='/static/css/viewer.min.css' type='text/css' media='all'/><script type='text/javascript' src='/static/js/viewer.min.js?1'></script><script type='text/javascript' src='/static/js/jquery-viewer.min.js'></script><script>jQuery.fn.wait = function (func, times, interval) { var _times = times || -1, //100次 _interval = interval || 20, //20毫秒每次 _self = this, _selector = this.selector, //选择器 _iIntervalID; //定时器id if( this.length ){ //如果已经获取到了,就直接执行函数 func && func.call(this); } else { _iIntervalID = setInterval(function() { if(!_times) { //是0就退出 clearInterval(_iIntervalID); } _times <= 0 || _times--; //如果是正数就 -- _self = $(_selector); //再次选择 if( _self.length ) { //判断是否取到 func && func.call(_self); clearInterval(_iIntervalID); } }, _interval); } return this; } $("table.syntaxhighlighter").wait(function() { $('table.syntaxhighlighter').append("<p class='cnblogs_code_footer'><span class='cnblogs_code_footer_icon'></span></p>"); }); $(document).on("click", ".cnblogs_code_footer",function(){ $(this).parents('table.syntaxhighlighter').css('display','inline-table');$(this).hide(); }); $('.nphpQianCont').viewer({navbar:true,title:false,toolbar:false,movable:false,viewed:function(){$('img').click(function(){$('.viewer-close').trigger('click');});}}); </script></body><!-- Matomo --><script> var _paq = window._paq = window._paq || []; /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); (function() { var u="https://tongji.php.cn/"; _paq.push(['setTrackerUrl', u+'matomo.php']); _paq.push(['setSiteId', '9']); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); })(); </script><!-- End Matomo Code --></html>