TAILIEUCHUNG - Wrox Professional CSS Cascading Style Sheets for Web Design phần 3

Như chúng ta đã đề cập, các quy tắc chứa trong một tờ sử dụng phong cách thường trọng ít hơn so với những người trong CSS của tác giả. Tuy nhiên, sự hiện diện của một quy tắc quan trọng hóa mối quan hệ này trên đầu của nó, một tờ khai của người sử dụng quan trọng là luôn luôn trọng hơn của tác giả, như thể hiện trong hình 2-17. | Best Practices for XHTML and CSS According to the CSS specification TR CSS21 important-rules the important rules create a balance of power between author and user style sheets. As we mentioned rules contained in a user style sheet are typically weighted less than those in the author s CSS. However the presence of an important rule turns this relationship on its head a user s important declarations are always weighted more than the author s as shown in Figure 2-17. Browser User Author Author important User important Figure 2-17 Style origin and the cascade from least to most important How does this affect our CSS Let s say that a browser is trying to determine the style for a basic paragraph element p . After parsing all available style sheets browser user and author all relevant styles are evaluated as shown in Listings 2-1 2-2 and 2-3. Listing 2-1 The Browser s Style Sheet p color 000 font-size 1em margin .9em 65 Chapter 2 Listing 2-2 The User s Style Sheet p color 060 important Listing 2-3 The Author s Style Sheet p color 300 font-size line-height padding 10px Let s set aside the user style sheet for a moment. Therefore for general users paragraphs will be styled according to this final calculated rule p color 300 font-size line-height margin .9em padding 10px author overwrites browser rule author overwrites browser rule specified only by author specified only by browser specified only by author Now if someone views your page with the user style sheet from Listing 2-2 the final result is changed somewhat p Color 060 font-size line-height margin .9em padding 10px user important rule overwrites author rule author overwrites browser rule specified only by author specified only by browser specified only by author Sort by Specificity Every selector is given a specificity rating which is yet another qualitative assessment of a selector s importance in the cascade TR CSS21 specificity .

Đã 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.