Học JavaScript qua ví dụ part 64

Các Chọn ID và thuộc tính của ID Các Chọn ID. Việc chọn ID là một cách khác để tạo ra một phong cách độc lập của một thẻ HTML cụ thể. Bằng cách sử dụng bộ chọn ID, bạn có thể chọn phong cách cho các phần tử bằng cách gán cho nó một mã số duy nhất. Tên của bộ chọn ID luôn được đặt một dấu thăng (còn được gọi là một dấu hiệu pound, #). Khối khai, bao gồm tài sản và giá trị, sau bộ chọn ID và được đính kèm trong dấu ngoặc nhọn. | 564 Chapter 14 Introduction to CSS Cascading Style Sheets with JavaScript EXAMPLE continued ul class square li circle li li square li li triangle li ul ul class none li Thanks li li Tack li li Gracias li ul body html EXPLANATION 1 A CSS class is defined for a list with different styles. 2 This is an HTML list item using the disc class. The output shown in Figure . Figure Using a CSS class to create different styles for lists. The ID Selector and the ID Attribute The ID Selector. The ID selector is another way to create a style that is independent of a specific HTML tag. By using the ID selector you can choose the style for the element by assigning it a unique ID. The name of the ID selector is always preceded by a hash mark also called a pound sign . The declaration block consisting of properties and values follows the ID selector and is enclosed in curly braces. From the Library of The ID Selector and the ID Attribute 565 FORMAT IDselector declaration EXAMPLE menu1 font-family arial font-size big color blue To apply an ID to an HTML tag use the id attribute. The attribute will be assigned the same name given to the ID selector so to apply an ID selector to a p tag you would stipulate p id name where name is the name of the ID selector see Example . The id Attribute. When JavaScript enters the picture the id attribute is used to identify each element as a unique object so that it can be manipulated in a JavaScript program. The id should be unique for an element and not used more than once on a page. If you need to use the style more than once for multiple elements it would be better to use the class selector instead. The ID selector can be used with a class selector of the same name as big .big . EXAMPLE html head title ID s title 1 style type text css 2 p font-family arial sans-serif helvetica font-style bold font-size 18 3 block The ID selector color red text-decoration underline style head body 4 p When making

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.