首页 > 解决方案 > 在 CSS 中,选择器“.class a”中的“a”是什么意思?

问题描述

我试图从 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”?

帮助和感谢!

标签: csscss-selectors

解决方案


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

<!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>


推荐阅读