|
But if you use CSS within javascript you are still using CSS syntax. The only thing you seem to be saying is that you've removed the need for selectors. Which you can do right now with inline styles, which I've been saying is not the best thing to do. If the CSS selectors for a page are difficult for you to understand then the problem lay in the HTML, not the CSS. 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. |
I'm advocating using whatever programming language you use to apply behaviour to your site, whether that be javascript or something else, to apply a style where it's needed, rather than via CSS selectors. Any language you're using to generate web pages will already have this functionality, because it's needed to e.g. attach event handlers (or equivalent) to text boxes. If your application uses jquery, use that (but it's probably not the best example, because jquery uses pretty much the same selector syntax). If your application uses some awful adobe templating engine and does everything via XPath, use that. If your application uses a java class hierarchy, use that. Etc.
>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.
I think javascript is already very much optimized for functions of the form: find some subset of the elements on the page, and then do something to them.
>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.
Unfortunately the W3C is unwilling to even add variables to CSS. Even if they did, it would be years before we could rely on new functionality being present in end-user browers - and then what if we realised we wanted some additional functionality? Better for the logic to be written in server-side code, and we can use new languages as they're invented. (With javascript we don't get to use new language features but we can at least use new libraries, which is more than can be said for CSS)
>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
Up to a point. Things like the box model there's no getting away from, but I see no need to use the CSS syntax or CSS selectors. Just like the way we currently handle the DOM, there can be a single styling API but you can use it in javascript with javascript syntax, or in python with python syntax, or in whichever language you like.
>Styles are not part of your markup, period. Well, maybe inline styles but, again, that's bad.
Without/before CSS, all styling was inline, i.e. part of your markup. The whole reason CSS was invented was, as I originally said, to provide a way to reuse (some small specific parts of) your markup in several places.