Home >
Web Front-end >
HTML Tutorial >
How to display multiple css rules in the same tag on the page? _html/css_WEB-ITnose
How to display multiple css rules in the same tag on the page? _html/css_WEB-ITnose
WBOY
Release: 2016-06-24 11:55:05
Original
1034 people have browsed it
In the past two days, I have been learning css and related to the impact of inline, external link, and embedding on the page: 1. Inline-----write the css code directly in html .Use the Inline CSS can effectively reduce HTTP requests, improve page performance, and relieve server pressure. Since the browser can render the page only after loading the CSS, it can prevent the CSS file from being unreadable and causing the page to run naked.
2. External link-----Store the CSS code as a separate file, such as aaa.css file containing all styles. External cascading in HTML is introduced using the tag statement. The sample code is as follows:
3. Embedded-----The CSS code Added directly to the modified markup element. The sample code is as follows:
ITEYE
The following are some problems you may encounter: 1. In inline style, if a tag uses multiple CSS rules at the same time, and these rules assign different values to the same attribute, which rule's attribute value is ultimately displayed on the page? The sample code is as follows:
ityeye
What is displayed on the page is the value of the attribute in the bbb rule. Because bbb is the last CSS rule that defines this attribute.
2. If a tag uses multiple CSS rules at the same time, and these rules exist in both inline and external styles, and the same attribute is assigned different values , which attribute value of the rule is finally displayed on the page? The sample code is as follows:
ityeye
.mmm{font-size:18px;backgroung-color:#FFF;}/*Written in the mmm.css file*/ What is displayed on the page is the value of the attribute in the bbb rule. Because bbb has a higher priority in the HTML page, and bbb is the last CSS rule to define this attribute in the HTML page.
3. If a tag uses multiple CSS rules at the same time, and these rules exist inline, external, or embedded in the tag, and If different values are assigned to the same attribute, which rule's attribute value is finally displayed on the page? The sample code is as follows:
ityeye< ;/div>
.mmm{font-size:18px;backgroung-color:#FFF;}/*Written in the mmm.css file*/ Displayed on the page is the value of the attribute embedded in the tag. Because rules embedded in tags have higher priority than inline and external ones.
Summary: When multiple CSS rules are used in the same tag, the priority displayed on the page is: embedded is higher than inline, and inline is higher than external. If there are different rules in the same inline or external style, it is related to the position of the rule in the CSS style sheet, and the attribute value of the CSS rule that last defined the attribute in the style sheet is displayed. Expressed in one sentence: the proximity principle, that is, which CSS rule is closest to which one is displayed.
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn