CSS (Cascading Style Sheets) is a language used to describe the layout and display effects of web pages. It can control the style, font, color, size, position, etc. of elements in HTML pages. This article will introduce the basic usage and implementation methods of CSS.
1. Basic usage of CSS
CSS is usually included in an HTML file or an external CSS file. CSS styles can be defined in the following two ways:
<head>
tag of HTML style> tag, for example:
<!DOCTYPE html> <html> <head> <title>CSS 实现方法</title> <style> body { background-color: lightblue; } h1 { color: white; text-align: center; } </style> </head> <body> <h1>这是一个标题</h1> <p>这是一个段落。</p> </body> </html>
body element is set to light blue,
h1 The text color of the element is white and it is centered.
tag, for example:
<!DOCTYPE html> <html> <head> <title>CSS 实现方法</title> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> <h1>这是一个标题</h1> <p>这是一个段落。</p> </body> </html>
styles.css file contains all CSS style definitions.
font-size attribute to change the font size, for example :
p { font-size: 18px; }
color attribute to change the font color, for example:
p { color: red; }
font-style attribute to change the font style, for example:
p { font-style: italic; }
width and
height attributes to change the width and height of the element, for example:
div { width: 200px; height: 100px; }
position and
left,
right,
top,
bottom attribute to change the position of the element, for example:
div { position: absolute; left: 100px; top: 50px; }
position attribute is set to
absolute, and then use
left and
top attributes to position the
div element to the middle of the page.
background-color attribute to change the background color of the element, for example:
body { background-color: lightblue; }
background-image attribute to set the background image, for example:
body { background-image: url("bg-image.jpg"); }
The above is the detailed content of Let's talk about the basic usage and implementation methods of CSS. For more information, please follow other related articles on the PHP Chinese website!