<p style="color: red; font-size: 16px;">这是一个红色的段落。</p>
style
attribute is used in the <p>
tag, and its value is color: red; font-size: 16px;
, indicating that the text color of this paragraph is red and the font size is 16 pixels. In this way, the paragraph will be displayed according to the specified style. <p>Second method: Embedded style sheet<p>Embedded style sheet means placing CSS style sheet information inside the <head>
tag of the HTML file. This method is more flexible than inline styles and can be modified for the entire page. The following is an example of an embedded style sheet: <head> <style> p { color: blue; font-size: 18px; } </style> </head> <body> <p>这是一个蓝色的段落。</p> </body>
<style>
tag in the <head>
tag, and then write CSS in it Style, such as p { color: blue; font-size: 18px; }
, means that the text color of all <p>
tags is blue and the font size is 18 pixels. In this way, all <p>
tags will be displayed according to the specified style. <p>The third method: external style sheet<p>External style sheet refers to saving CSS style information in a separate CSS file and passing it through <link> in the HTML file ;
tag refers to this file. This method can reduce the size of HTML files and improve page loading speed. Here is an example of an external style sheet: <head> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <p>这是一个黑色的段落。</p> </body>
<link>
tag in the <head>
tag to reference the CSS file, such as < ;link rel="stylesheet" type="text/css" href="style.css">
means introducing the external style sheet file style.css
into the current HTML file. In the style.css
file, you can define all the required CSS styles: p { color: black; font-size: 20px; }
<p>
tags is black and the font size is 20 pixels.
<p>To sum up, there are three ways to modify CSS styles: inline styles, embedded style sheets and external style sheets. Each method has its applicable scenarios, and the specific use needs to be selected according to the page situation and needs. When designing a Web page, choosing the appropriate CSS style modification method can make the page more beautiful, easier to read, and improve user experience. The above is the detailed content of css style modification. For more information, please follow other related articles on the PHP Chinese website!