- 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.
- ASP.NET Core:Cloud-ready,Enterprise Web Application Development
- Microsoft Exchange Server PowerShell Cookbook(Third Edition)
- Angular UI Development with PrimeNG
- Python自動化運維快速入門(第2版)
- Developing Middleware in Java EE 8
- 移動界面(Web/App)Photoshop UI設計十全大補
- HTML5與CSS3基礎教程(第8版)
- Mockito Essentials
- 數據分析與挖掘算法:Python實戰
- R的極客理想:量化投資篇
- HTML5移動Web開發
- 人人都能開發RPA機器人:UiPath從入門到實戰
- 零基礎學Java第2版
- MySQL數據庫教程(視頻指導版)
- 前端Serverless:面向全棧的無服務器架構實戰