Abstraction away from CSS

前端 未结 18 1765
别跟我提以往
别跟我提以往 2021-02-13 10:34

Many frameworks seek to abstract away from HTML (custom tags, JSFs component system) in an effort to make dealing with that particular kettle of fish easier.

Is there an

相关标签:
18条回答
  • 2021-02-13 11:12

    @SCdF: I think your summary here is fair. But the argument that some people don't have the time to learn CSS is bogus - just think about for a second. Substitute a technology that you've mastered and you'll see why:

    I. Hate. Java. Is there something out there that will just write it for me? Not everyone has the time to master Java.

    CSS is certainly an imperfect technology - I have high hopes that 5 years from now we won't be dealing with browser incompatibilities any more (we're almost there), and that we'll have better author-side tools (I've written a Visual Studio macro for my own use that provides the the sort of variables and calculations that you describe, so it's not impossible) - but to insist that you should be able to use this technology effectively without really understanding it just isn't reasonable.

    0 讨论(0)
  • 2021-02-13 11:13

    Then comes the multiple browser issue

    There is this that helps remove some inconsistencies from IE. You can also use jQuery to add some selectors via javascript.

    I agree with Dan, learn it and it's not so much of a problem, even fun.

    0 讨论(0)
  • 2021-02-13 11:14

    This elaborates on my previous answer.

    When I first started using CSS I also thought it was a pain that it didn't support variables, expressions, etc. But as I started to use it more and more, I developed a different style to overcome these issues.

    For example, instead of this:

    a { color: red }
    .entry { color: red }
    h1 { color: red }
    

    You can do:

    a, .entry, h1 { color: red }
    

    You can keep the color declared in one spot by doing this.

    Once you use CSS enough you should be able to overcome most browser inconsistencies easily. If you find that you need to use a CSS hack there is probably a better way to do it.

    0 讨论(0)
  • 2021-02-13 11:14

    Solutions to problems seem to often involve jiggering numbers around like some chef trying to work out exactly how much nutmeg to put in his soon-to-be famous rice pudding

    I only get this when trying to make stuff work in IE.

    If you learn CSS to the point where you can code most things without having to look up the reference (if you're still looking up reference regularly you don't really know it and can't claim to complain I think), and then develop for firefox/safari, it's a pretty nice place to be in.

    Leave the pain and suffering of IE compatibilit to the end after it works in FF/Safari, so your mind will attribute the blame to IE, where it damn well belongs, rather than CSS in general.

    0 讨论(0)
  • 2021-02-13 11:18

    For variable support, I have used PHP with CSS headers to great effect for that. I think you can do it in any language. Here is a php sample:

    <?
    header('content-type:text/css');
    header("Expires: ".gmdate("D, d M Y H:i:s", (time()+900)) . " GMT"); 
    
    $someColorVar = "#cc0000";
    ?>
    BODY {
          background-color: <?= someColorVar ?>;
         }
    
    0 讨论(0)
  • 2021-02-13 11:18

    CSS variables are coming (relatively) soon, but I agree they are long overdue. In the meantime, it is possible to use a CSS templating engine such as Sass, or even the dynamic web language of your choice, to generate your stylesheets programmatically.

    0 讨论(0)
提交回复
热议问题