Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the browser find and render CSS rules

Let's say we have a page with the some simple HTML/CSS like below. Does the browser also read .b and .c in the stylesheet?

HTML

<div class="a">1</div>
<div>2</div>
<div>3</div>

CSS

.a { color: aqua; }
.b { color: blue; }
.c { color: cyan; }

That is just an example, but in the real world there might be hundreds, thousands lines of CSS code isn't being used, such as using Bootstrap for a very very small project.

like image 511
Stickers Avatar asked Feb 19 '15 20:02

Stickers


1 Answers

Yes all the rules are loaded in the memory, this is why when you add new element to your DOM (e.g. by using javascript) you see that the style automatically applies to them.

like image 136
Almis Avatar answered Sep 16 '22 13:09

Almis