将类型选择器与id选择器组合的优点是什么?例如div#some_id [英] What are the advantages of combining a type selector with an id selector? e.g. div#some_id

查看:96
本文介绍了将类型选择器与id选择器组合的优点是什么?例如div#some_id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这很简单,但我想知道为什么人们会这样写?

This is extremely simple but I am wondering why people write this?

div#some_id

网页上只能有一个名称为some_id的ID。那么为什么要具体呢?是否为了可读性目的?

You can only have one ID of that name "some_id" on a webpage. So why be specific with it? Is it for readability purposes?

推荐答案

有以下几种可能的原因:

There are a couple of possible reasons:


  • 这是更多具体 selector

  • 它告诉读取样式表的人选择器的目标是div元素

  • 同样的id可以应用于不同的元素类型不同的页面使用相同的样式表(这通常会导致更多的混乱然后利益,所以我不会建议这种方法)。

  • It is a more specific selector
  • It tells people reading the stylesheet that the selector is aiming at a div element
  • The same id could be applied to different element types on different pages that use the same stylesheet (this usually causes more confusion then benefits though, so I wouldn't advise that approach).

这篇关于将类型选择器与id选择器组合的优点是什么?例如div#some_id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆