css - 如何在 SCSS 中使用类名定位标签
问题描述
我有一个 HTML 元素如下
<a class="button">Click</a>
在我的 .scss 文件中,我有以下代码。
.button{
& a{
color:red;
&:hover,
&:visited{
color:blue;
}
}
}
上面的代码不起作用。
我尝试搜索诸如“使用 css 定位兄弟类”之类的术语,但结果显示了如下所示的场景。
<a>
<span class="button">Click</span>
</a>
如何a
使用按钮类定位标签?
更新 :
我不是要针对父元素。我需要定位使用特定类的元素。
解决方案
标记名称后跟选择器(类或 id)名称,如a.class_name
,div.class_name
或a#class_name
,div#class_name
div.button{ /* tag name followed by selector(class or id) name*/)
&>a{ /*will select only direct '<a> tags' inside div.button */
color:red;
&:hover,
&:visited{
color:blue;
}
}
}
div.button{ /* tag name followed by selector(class or id) name*/)
& a{ /*will select only all '<a> tags' inside div.button */
color:red;
&:hover,
&:visited{
color:blue;
}
}
}
div.button{ /* tag name followed by selector(class or id) name*/)
& a.link{ /*will select only '<a> tags with classname link' inside div.button */
color:red;
&:hover,
&:visited{
color:blue;
}
}
}
<div class="button"><a class="link" href=""></a></div>
推荐阅读
- python - 难以对列表进行排序
- reactjs - 前端经过身份验证的请求 Google Cloud Storage
- rust - 如何打破 Err 创建
- assembly - 使用 TYPE 指令汇编 MASM x86
- python - 绘制变量增加的方程python
- c - 错误:控制可能到达非 void 函数 c 编程的结尾
- javascript - React-router 未呈现动态组件-单击时没有任何反应
- javascript - 退出时,Firebase 在数据库侦听器上出现错误
- android - 从非对称算法中的私钥解析时开始出现未知字符
- recursion - Prolog peano 数字差/减法