#登录CSS选择器 [英] # sign in CSS selectors

查看:89
本文介绍了#登录CSS选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一些CSS选择器在它们前面有,这意味着什么?

Some CSS selectors have # in front of them, what does that mean?

推荐答案

这是ID选择器,是CSS标准的基本特征。它根据 id 属性(假设符合文档,当然),将HTML元素与给定的ID匹配。有关详情,请参见 W3C Selectors规范

It's the ID selector, a fundamental feature of the CSS standard. It matches the HTML element with the given ID, according to the id attribute (assuming a conforming document, of course). See the W3C Selectors spec for more.

<!DOCTYPE html>
<html lang="en">

<head>
  <style type="text/css">
  #my-div {
      color: #f00;
  }
  </style>
</head>

<body>
  <div id="my-div">This text will be red.</div>
  <div id="another-div">This text will not be red.</div>
</body>

</html>

您也可能看到表示法用在URL片段标识符中以引用命名锚(< a name =some-anchor>< / a> )。这些还可以指向页面中具有特定ID的元素,就像命名锚点一样,并且我认为这就是为什么CSS在选择ID时使用相同的符号。

You may also have seen the # notation used in a URL fragment identifier to refer to named anchors (<a name="some-anchor"></a>). These can also point to elements with certain IDs in your page, just like named anchors, and I gather that it's why CSS uses the same notation for selecting IDs.

这篇关于#登录CSS选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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