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

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.

主站蜘蛛池模板: 凤台县| 家居| 锡林浩特市| 徐州市| 丰县| 潼南县| 临颍县| 朝阳市| 定结县| 徐闻县| 汾阳市| 荥阳市| 萨迦县| 兴化市| 子洲县| 涟水县| 泾阳县| 定南县| 玉溪市| 海宁市| 芷江| 五寨县| 怀远县| 上杭县| 栖霞市| 安化县| 雅江县| 阿拉尔市| 武穴市| 临武县| 于都县| 涿鹿县| 巴彦淖尔市| 永州市| 江阴市| 日土县| 许昌县| 信阳市| 永清县| 江川县| 石首市|