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

  • The HTML and CSS Workshop
  • Lewis Coulson Brett Jephson Rob Larsen Matt Park Marian Zburlea
  • 196字
  • 2021-06-11 12:54:56

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.

主站蜘蛛池模板: 扎鲁特旗| 金堂县| 双鸭山市| 淳安县| 麻阳| 平遥县| 肥城市| 明光市| 玉林市| 罗江县| 砀山县| 屏南县| 泗洪县| 霍林郭勒市| 烟台市| 嘉义县| 南乐县| 鄂尔多斯市| 吉木乃县| 香格里拉县| 阜南县| 牙克石市| 浦东新区| 淮北市| 芜湖县| 临城县| 兴和县| 雷波县| 长岭县| 夏津县| 景东| 英超| 谢通门县| 五峰| 应城市| 大丰市| 阿拉善左旗| 民勤县| 遂平县| 麻阳| 娱乐|