question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Conditional CSS Code

See original GitHub issue

How about having something like conditional css code depending upon variable


@has_theme_support: true;

.awesome-class {
    width: 100px;
    height: 200px;
    margin: 0 auto;

    /* Adds theme support if @has_theme_support is 'true'; */
    if( @has_theme_support ){
        background: green;
        color: yellow;
    }
}

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Reactions:6
  • Comments:60 (33 by maintainers)

github_iconTop GitHub Comments

10reactions
valllabhcommented, Apr 24, 2013

Yes I know that but if we are writing huge LESS we have to write and manage hundreds of .mixins I don’t think mixin solves this issue. Even mixins will get lot of power with this feature. Less CSS almost have all the feature that some programming language has then why not this ?

.button-maker (@style: 'light') {
    cursor: pointer;
    display: inline-block;
    padding: 5px 10px;

    if(@style == 'light'){
        /* adds light styling */
    }

    if(@style == 'dark'){
        /* adds dark styling */
    }
}
7reactions
aukgitcommented, May 3, 2016

I think ‘sass’ is better than less. It already has if-else. It is really hard and many lines of coding the less. When works but it doesn’t full fill the need. Additionally we can make loops in less but language should have it’s own feature.

less scss

Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS Conditional Rules - CSS: Cascading Style Sheets | MDN
CSS Conditional Rules is a CSS module that allows to define a set of rules that will only apply based on the capabilities...
Read more >
Can you use if/else conditions in CSS? - Stack Overflow
CSS has a feature: Conditional Rules. This feature of CSS is applied based on a specific condition. Conditional Rules are: @supports.
Read more >
if/else condition in CSS - GeeksforGeeks
Given an HTML file and we need to apply using if-else conditions in CSS. No, We can not use if-else conditions in CSS...
Read more >
CSS Conditional Rules Module Level 3 - W3C
Each conditional group rule has a condition, which at any time evaluates to true or false. When the condition is true, CSS processors...
Read more >
Use CSS to change the style of each row depending on the ...
Templates help display your data. But if your template requires rules to be applied to specific CSS selectors, using Conditional Display is the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found