Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: #id .class VS .class performance. Which is better?

I'd assume that this would be faster:

#dialog .videoContainer { width:100px; }

than:

.videoContainer { width:100px; }

Of course disregarding that .videoContainer in the first example would only be styled under the #dialog tag.

like image 304
Ryan Avatar asked Oct 02 '11 00:10

Ryan


People also ask

What CSS means?

HTML (the Hypertext Markup Language) and CSS (Cascading Style Sheets) are two of the core technologies for building Web pages. HTML provides the structure of the page, CSS the (visual and aural) layout, for a variety of devices.

What is CSS and why it is used?

CSS stands for Cascading Style Sheets, and it's used to add style to a web page by dictating how a site is displayed on a browser. CSS is unique in that it doesn't create any new elements, like HTML or JavaScript. Instead, it's a language used to style HTML elements.

What is CSS programing?

CSS (Cascading Style Sheets) is a language for styling the webpage. We can change the appearance and the layout of the webpage by using CSS. We can also define how a website's view changes in different screens like desktops, tablets, and mobile devices. CSS is not a programming language, like C++ or JavaScript.


1 Answers

CSS selectors are matched from right to left.

Therefore, .videoContainer should be "faster" than #dialog .videoContainer because it misses out testing for #dialog.

However, this is all irrelevant at best - you'll never notice the difference. For normally sized pages, the amount of time we're talking about is so insignificant as to be nonexistent.

Here's a relevant answer by an expert that you should read: Why do browsers match CSS selectors from right to left?

like image 108
thirtydot Avatar answered Sep 28 '22 16:09

thirtydot