【问题标题】:In CSS, what does the "a" mean in the selector ".class a"? [duplicate]在 CSS 中,选择器“.class a”中的“a”是什么意思? [复制]
【发布时间】:2021-02-07 06:20:42
【问题描述】:

我正在尝试从 w3schools 中找出这个 CSS 示例:

.sidenav {
  height: 100%;
  width: 0;
  position: fixed;
  z-index: 1;
  top: 0;
  left: 0;
  background-color: #111;
  overflow-x: hidden;
  transition: 0.5s;
  padding-top: 60px;
  text-align:center;
}

.sidenav a {
  padding: 8px 8px 8px 32px;
  text-decoration: none;
  font-size: 25px;
  color: #818181;
  display: block;
  transition: 0.3s;

}

很明显,sidenav 是元素的类,人们可能会认为“a”是转换后 sidenav 的选择器......但我找不到带有示例的直接定义,所以我正在寻找我的上级在我开始滥用它之前在这里澄清一下。

简而言之,“a”是什么?

帮助和感谢!

【问题讨论】:

  • CSS 中有三种基本标识符:.class#idhtml_element。不同的标识符由空格区分。因此,您的查询 CSS 表示“应用于作为 .sidenav 类的后代的锚 HTML 元素。”

标签: css css-selectors


【解决方案1】:

基本上a 将用于html 中的<a href=""></a> 标记,但这意味着您在sidenav 中选择a 标记。例子:

<!DOCTYPE html>
 <html>
  <head>
<style>
div a {
 text-decoration: none;
}
</style>
  </head>
<body>
<div>
 <a href="#">I don't have an underline because I was selected in the div a</a>
</div>
<a href="#">I have an underline because I was not selected</a>
</body>
 </html>

【讨论】:

    猜你喜欢
    • 2021-09-18
    • 2011-04-16
    • 2021-03-31
    • 2011-03-10
    • 2019-02-05
    • 1970-01-01
    • 1970-01-01
    • 2016-12-14
    相关资源
    最近更新 更多