iidear / blog

blog
0 stars 0 forks source link

CSS #5

Open iidear opened 5 years ago

iidear commented 5 years ago

CSS is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, in speech, etc. w3c

iidear commented 5 years ago

CSSOM

CSSOM defines APIs (including generic parsing and serialization rules) for Media Queries, Selectors, and of course CSS itself. CSSOM

js 写的 css parser cssom

在线解析器 CSSOM Parser

示例

css 源代码

h1.title {
  font-size: 24px;
  color: red;
}

section .container {
  width: 100%;
  border: 1px solid #DDD;
}

解析结果

{
    parentStyleSheet: null,
    cssRules: [
        {
            parentRule: null,
            parentStyleSheet: "../..",
            selectorText: "h1.title",
            style: {
                0: "font-size",
                1: "color",
                length: 2,
                parentRule: "..",
                _importants: {
                    "font-size": "",
                    color: ""
                },
                __starts: 9,
                "font-size": "24px",
                color: "red"
            },
            __starts: ,
            __ends: 45
        },
        {
            parentRule: null,
            parentStyleSheet: "../..",
            selectorText: "section .container",
            style: {
                0: "width",
                1: "border",
                length: 2,
                parentRule: "..",
                _importants: {
                    width: "",
                    border: ""
                },
                __starts: 66,
                width: "100%",
                border: "1px solid #DDD"
            },
            __starts: 47,
            __ends: 110
        }
    ]
}