官术网_书友最值得收藏!

CSSOM

The CSS Object Model (CSSOM) is similar to the HTML DOM, which we described earlier. The CSSOM is an in-memory representation of the styles in the document as they are computed on elements. It is a tree-structure with nodes that mirror those in the HTML DOM, and the objects associated have a list of style properties where all CSS rules have been applied.

The CSSOM represents all the styles that have been created in the document as objects with properties that we can change with JavaScript. We can access these styles and change the values of style properties.

We mostly access these styles via the styles property of a DOM element, as here:

const boldElement = document.querySelector('.aBoldElement');

boldElement.styles.fontWeight = 'bold';

In JavaScript, we can also access the CSSOM with the getComputedStyles method on the window object; for example:

const boldElement = document.querySelector('.aBoldElement');

window.getComputedStyles(boldElement);

This will return a computed styles object for an element with the aBoldElement class attribute. This method returns a read-only styles object with all computed styles for the element.

In the next section, we will look at the different CSS selectors we can use to apply our styles to a web page.

主站蜘蛛池模板: 晋中市| 政和县| 乌拉特中旗| 娱乐| 姜堰市| 滕州市| 伊金霍洛旗| 邢台县| 京山县| 孟津县| 高尔夫| 金塔县| 海门市| 米易县| 十堰市| 宁蒗| 孝昌县| 东方市| 东乌珠穆沁旗| 皮山县| 阿拉善盟| 大邑县| 钟山县| 兴隆县| 东阿县| 沾化县| 安泽县| 罗江县| 东安县| 五华县| 芒康县| 潞城市| 南汇区| 文成县| 长春市| 黄骅市| 银川市| 青河县| 出国| 土默特右旗| 应用必备|