2017-05-17 46 views
1

非常新的Scss/Sass在我的mod.scss文件的其他地方,编写了我经常重复使用的样式Ul > li。但是,在另一个mod.scss文件中,我需要为单个特定实例更改此代码。SCSS引用元素的特定实例

是否有可能实质上创建一个if-like声明:“如果UL/LI标签出现在.content-section类别下,则采取行为X,Y和z”?

.content-section 
{ 
    margin: 40px 0px; 

    & .siteTitleText 
    { 
     margin-bottom: 50px; 
    } 

    & .headers 
    { 
     margin-bottom: 30px; 
    } 

    img 
    { 
     margin: 30px 0px; 
    } 

    *ul* 

} 

HTML:

<div class="content-section vendors"> 
    <p class="headers">Modules, partials, and vendor</p> 
    <p class="bodyText">As you can see this divides my project into three basic types of files. Modules, partials, and vendored stylesheets.</p> 
    <ul> 
     <li class="bodyText">The modules directory is reserved for Sass code that doesn't cause Sass to actually output CSS. Things like mixin declarations, functions, and variables.</li> 

     <li class="bodyText">The partials directory is where the meat of my CSS is constructed. A lot of folks like to break their stylesheets into header, content, sidebar, and footer components (and a few others). As I'm more of a SMACSS guy myself, I like to break things down into much finer categories (typography, buttons, textboxes, selectboxes, etc…).</li> 

     <li class="bodyText"></li> 
    </ul> 
</div> 
+0

你能也分享你的HTML结构? – Roberrrt

+1

当然,我将编辑帖子 –

+0

“under”是指“.content-section”的后裔还是物理上位于页面布局下方? – amflare

回答

1

使用+在代码中选择关闭标签下下一场比赛。 如果您想在.content-section内选择子女标签,只需简单地嵌套标签即可。

参考:w3 documentation

.content-section { 
    margin: 40px 0px; 

    & .siteTitleText { 
     margin-bottom: 50px; 
    } 

    & .headers { 
     margin-bottom: 30px; 
    } 

    img { 
     margin: 30px 0px; 
    } 

    ul, li { // If .content-section has a child named ul or li, do this: 
     margin: 100px; 
    } 
} 
+0

我对OP的理解是,他们的意思是当'ul'是'.content-section'的孩子而不是兄弟姐妹。 – robin

+0

虽然有点不清楚,让我们问@TheodoreSteiner自己。 – Roberrrt

+0

大家好,我很抱歉,是的,我的意思是一个孩子 –