<style>
tag. You can define all the CSS styles you need in the <style>
tag, so that the HTML page will apply the CSS styles to the document when it loads. For example, the following example: <!DOCTYPE html> <html> <head> <title>我的网页</title> <style> body { background-color: blue; } h1 { color: white; text-align: center; } </style> </head> <body> <h1>欢迎来到我的网页</h1> <p>这是我的第一个网页</p> </body> </html>
<style>
tag Be white and center aligned. <p>2. Use external CSS files<p>If you want to use the same CSS style in multiple HTML pages, then using internal CSS will be very redundant. At this time we can use external CSS document. We create a new file with the .css suffix, such as style.css, and link the CSS style file to the page through the <link>
tag in the head tag of the HTML page. For example: <!DOCTYPE html> <html> <head> <title>我的网页</title> <link rel="stylesheet" href="style.css"> </head> <body> <h1>欢迎来到我的网页</h1> <p>这是我的第一个网页</p> </body> </html>
body { background-color: blue; } h1 { color: white; text-align: center; }
<!DOCTYPE html> <html> <head> <title>我的网页</title> </head> <body> <h1 style="color: white; text-align: center;">欢迎来到我的网页</h1> <p style="background-color: blue;">这是我的第一个网页</p> </body> </html>
<h1>
tag and the <p>
tag to define the title respectively color and alignment, as well as the background color of the paragraph.
<p>Summary
<p>Whether it is internal CSS, external CSS files or inline CSS, their ultimate purpose is to beautify the appearance of the web page. In actual development, we can choose different ways to link CSS and HTML according to the actual situation. When there are more CSS styles to be defined, we can use external CSS files; when there are fewer styles to be defined, we can use internal CSS or inline CSS. The above is the detailed content of How to connect css and html. For more information, please follow other related articles on the PHP Chinese website!