Trong CSS, bộ chọn element được dùng để chọn các HTML elements cần định kiểu. Trong một khai báo bộ chọn, có tên HTML element. Các thuộc tính CSS áp dụng cho element đó được viết bên trong dấu ngoặc {}.
Syntax:
element {
\\ CSS property
}
Example 1: Ví dụ này minh họa bộ chọn element trong CSS.
html<!DOCTYPE html>
<html>
<head>
<title>element selector</title>
<style>
/* h1 element selected here */
h1 {
color: green;
text-align: center;
}
/* h2 element selected here */
h2 {
text-align: center;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>element Selector</h2>
</body>
</html>
Output:
Example 2: Ví dụ này cũng minh họa bộ chọn element trong CSS.
html<!DOCTYPE html>
<html>
<head>
<title>element selector</title>
<style>
h1 {
text-align: center;
}
h2 {
text-align: center;
color: green;
font: bolder cursive;
}
form {
text-align: center;
}
</style>
</head>
<body>
<h1>FORM</h1>
<h2>Please fill in details:</h2>
<form action="#">
Name: <input type="text" value="name"><br>
Age: <input type="text" value="age"><br>
City: <input type="text" value="City"><br>
</form>
</body>
</html>
Output:
Supported Browsers: Các trình duyệt được hỗ trợ bởi bộ chọn element được liệt kê dưới đây:
- Google Chrome
- Internet Explorer
- Firefox
- Safari
- Opera