热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用SASS在元素内定位元素-TargetelementsinsideanelementwithSASS

Ihavealabeloutsideaformandlabelsinsodeaform.IwanttouseSASStostylethelabelsinsod

I have a label outside a form and labels insode a form. I want to use SASS to style the labels insode the form different. Here the html:

我在表单外面有一个标签,标签在表格中。我想使用SASS来标记不同形式的标签。这里的html:

I thought I could do:

我以为我能做到:

.loginField 
    {

       label 
       {
       //css rules for label outside form
       }

       &form{

             label{
             //css rules for label insode the form
             }
        }
     }

However, this does not produce CSS rules for the inner labels - they get applied the same styles as the label outside the form...

但是,这不会为内部标签生成CSS规则 - 它们应用与表单外部标签相同的样式...

1 个解决方案

#1


0  

You just need to specify the direct child relationship of the top label

您只需指定顶部标签的直接子关系

SASS

.loginField 
    {

       > label 
       {
       color:red;
       }

       & form{ /* note the space */

             label{
             color:green
             }
        }
     }

CSS

.loginField > label {
  color: red;
}
.loginField form label {
  color: green;
}

推荐阅读
author-avatar
小女人的忧伤--
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有