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

Calculating the weight of selectors

A class is worth 10 points, so .secondary-section is worth 10 points. A plain old element such as p or div is worth 1 point. Therefore, the .secondary-section p selector is 11 points. The .secondary-section div figure img selector is 13 points. Let's create another selector below the one worth 13 points and we have .secondary-section img. Then, let's change the border-color to blue:

.secondary-section div figure img { 
   border: 10px solid #333; 
} 
.secondary-section img {
border: 10px solid blue;
}

When we save this, our border is going to remain gray because the point value of our last selector is only 11; it's getting beat out by the previous selector's point value of 13. That's the problem with these long descendant selectors that are longer than they should be, they get weighted heavier:

Following is the output of preceding code:

IDs have a point value of 100 points, which is why I advise against using them. They have so much unnecessary weight to them and drive the specificity level through the roof. Assigning point values kind of sounds like keeping score on a video game, but the difference is you want to try and keep your point value as low as possible on this game. If you do that, you will be able to write less complicated CSS.

主站蜘蛛池模板: 明星| 将乐县| 额济纳旗| 昭平县| 肥西县| 太保市| 临海市| 潞西市| 漳浦县| 榆林市| 神池县| 永川市| 乌鲁木齐县| 曲阳县| 锦屏县| 时尚| 乐平市| 临湘市| 赣榆县| 大邑县| 宜都市| 营山县| 阿图什市| 黑河市| 尤溪县| 无极县| 个旧市| 东乌珠穆沁旗| 浮梁县| 沙雅县| 林州市| 安顺市| 绥江县| 平潭县| 睢宁县| 冕宁县| 沙河市| 定安县| 高唐县| 昭苏县| 灌云县|