CSS selectors
CSS selector
#CSS selector is divided into two types
Id and Class Selectors
#If you want to set CSS styles in HTML elements, you need to set the "id" and "class" selectors in the element.
#id selector
The id selector can specify a specific style for HTML elements marked with a specific id. The HTML element uses the id attribute to set the id selector, and the id selector in CSS is defined with "#". The following style rules apply to the element attribute id="para1":Run the program to try itphp中文网(php.cn) php中文网(php.cn)
这一段不受css样式影响。
The ID attribute should not start with a number. IDs starting with numbers do not work in Mozilla/Firefox browsers.
class selector
class selector is used to describe the style of a group of elements. The class selector is different from the id selector. , class can be used in multiple elements. The class selector is represented by the class attribute in HTML. In CSS, the class selector is displayed with a dot ".": In the following example, all objects with the center class HTML elements are all centered.Example
Run the program to try itphp中文网(php.cn) 标题居中
段落居中。
You can also specify specific HTML elements using classes. In the following example, all p elements use class="center" to center the text of the element:
Example
Run the program and try itphp中文网(php.cn) 这个标题将不会受到影响
这一段将居中对齐
The first character of the class name cannot use numbers! It won't work in Mozilla or Firefox.