| >What's the difference between this:
>STYLE.on("element", {textAlign: "center", fontSize: 50})
>or this:
>element style="text-align: center; font-size: 50px;"
>or this: .element {text-align: center; font-size: 50px;} The difference is that CSS has its own syntax, its own semantics, and its own set of gotchas to learn, different from any other language. (Obviously for a simple selector like .element it's easy to know what it's going to refer to, but CSS is not limited to things that are so clear). >Now, if you need to change that text-align to left you have to change every instance of it throughout your code, except for the third where it only needs to be changed once. Only if you're a muppet. Your HTML is being generated by a program; that program should have a single place where it knows what the text-align of this class (in the general sense of the term) of elements should be, and you can change it in that one place if you want to change it. >Plus, there's the issue that if you want this web page to be indexed by search engines you're going to have problems. If people have turned javascript off or use a white list to control scripts then this page simply will not work with very little available fallback. Right; it only makes sense to use javascript if you're already using javascript for major functionality. That's what I'm really advocating for here: write your styling logic in the same language as the rest of your site's logic. >Keep in mind this thread started for me because of your statement that CSS is not powerful enough to express styling when that's exactly what it does and all that it does. My point was that it isn't powerful enough to express your styling in a fully abstracted way. E.g. if your website's general colour scheme is blue and you have parts that are a light blue, a mid blue and a dark blue, CSS doesn't let you define these colours in terms of each other - so if you want to change it to be green, you have to change three different colour definitions. Because of this kind of thing, people use pre-processors like LESS - which means using yet another language with its own syntax and logic to learn, when you're already using a perfectly good programming language to generate most of your site. >CSS selectors let you target elements in your markup to style them, nothing else. You can use these selectors to reuse your CSS stylings for duplicate elements that require the same styling. Yes, that was why I took pains to say "some small specific parts of your markup". Your styles are part of your markup, at least traditionally. |
I guess I'm a muppet that doesn't understand how you avoid having to update lines of code all over the place when your code is sprinkled with inline styles. Unless you are advocating using some kind of class system for styling within javascript, which is odd since CSS already offers that. If you are speaking of applying CSS classes through javascript, which sounds like what you are describing, then I'm confused over what the point is. You can create CSS classes and apply them to elements on the fly right now, you just seem to saying you want to create the CSS classes in javascript. Which makes no sense when you can do the exact same thing more efficiently in an external style sheet. The reason it is more efficient is because those classes will not need to be created on every single page load.
So your answer to the problems I point out is to ignore the problems I point out. Sure, use javascript for everything and wonder why no one can find your site on their favorite search engine or why some people cannot see your site at all. I understand what you're saying about writing your styling in javascript, which is really CSS, but you are skipping over the problems I point out that are inherent in that solution.
I've already agreed that CSS has serious limitations and that pre-processors (even domo) attempt to address them, some do so quite well. The syntax that SASS and Less use is actually existing CSS syntax with extensions, there's very little new syntax to learn. I would say your solution has more of a learning curve involved because you are adding completely new syntax and logic to javascript when it wasn't designed to do these things. The solution is to update what the browsers expect from CSS. There is no reason why CSS itself cannot be extended to do what you are speaking of, probably most people (including me) would want that functionality right now. But again, the very thing you speak of is CSS, syntax and all, it changes nothing other than how you code it. Much like my three examples you pretty much ignored, you still have to learn the CSS syntax and capabilities regardless of how you feed it to browser. Unless you advocate coming up with a whole new styling language that eventually outputs to CSS, which is required because that's what the browsers expect. In the end, it doesn't matter how you use CSS but you are advocating an inefficient way of doing it.
As I said before, creating a more inefficient output for the sake of maybe, just maybe, slighly more efficient input is not the solution. What you want is to reverse the progress that's been made over the last ten years or so because you can't be bothered to learn some of the easiest syntax in the industry. Well, actually with your solution you still have to learn the same syntax. It's not even as if HTML and CSS were programming languages. There's next to no functionality involved with these two. I would say what you want would make these things more complicated for the coder and less useful to the end-user.
Again, CSS has nothing at all to do with markup. Saying "small specific part of your markup" doesn't qualify your statement, since it doesn't actually do that. Styles are not part of your markup, period. Well, maybe inline styles but, again, that's bad. Sure, you can add classes and ids to your markup for CSS to use as selectors but even then they are not required. Plus the fact that ids are already needed within HTML for various things and using classes with javascript libraries such as jQuery (javascript is almost ready out of the box to do this itself) has become almost standard. Basically, you are already using for other purposes the very things that CSS needs to make coding easier, yet you say selectors are difficult and confusing to use. If they are difficult and confusing to use then you shouldn't be using them in javascript, which I bet you do. The closest to providing markup in CSS is with using :after or :before pseudo-classes with the content property, which has its uses but severely limited. But you've given up on pseudo-classes so that is irrelevant to you.
I haven't even brought up the serious accessibility problems this solution has which can get you sued in the real world, or the US at least.
By the way, stimulating conversation we have here.