简体   繁体   English

是否可以创建一个CSS / SASS混合来检测当前URL?

[英]Is it possible to create a CSS/SASS mixin that detects current URL?

I just found out CSS's @media is a mixin that takes different parameters like width/height/orientation etc. to determine what device is used and then the mixin applies some basic CSS styles. 我刚刚发现CSS的@media是一个mixin,它采用不同的参数(例如width / height / orientation等)来确定要使用的设备,然后mixin应用一些基本的CSS样式。

My question is whether it is possible to create a very similar mixin called for example @address that would be able to determine current URL and then apply some basic CSS styles. 我的问题是,是否可以创建一个非常相似的混入(例如@address ,该混入可以确定当前URL,然后应用一些基本的CSS样式。 Something that could be used this way: 可以通过这种方式使用的东西:

@address ("https://stackoverflow.com") {    

    /*if URL is https://stackoverflow.com then apply following styles*/

    h1 {
        color: red;
        font-size: 2.1em;
    }

    #myElement {
        background: #FFF;
        border: 1px solid #000;
    }
}

If this is possible How do I create such mixin? 如果可能的话,如何创建这样的mixin? If not, why? 如果没有,为什么?

No. It is clearly not possible. 不,这显然是不可能的。 If its helpful for you, you can only catch elements with href attribute. 如果对您有帮助,则只能捕获具有href属性的元素。 I'm sharing cause its about using links. 我正在分享其使用链接的原因。

 pa { color: #333 } pa[href="https://stackoverflow.com"]{ text-decoration: none; } 
 <p> <a href="https://stackoverflow.com">stackoverflow.com</a> </p> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM