Exteranl CSS - Makes Code Fragile ?
I've been having a debate with my self recently.
If I use className then I can no longer post code or hand out a snippets that actually work by themselves. They have to be accompanied by a CSS file, which if lost will cause the code to break (often invisibly to the person trying to use it).
On the other hand, doing something like:
is a heck of a lot easier than
WhiteOutDiv.className = "someclassname";
var currOpacity = 50;
WhiteOutDiv.style.display = 'none';
WhiteOutDiv.style.zIndex = "499";
WhiteOutDiv.style.position = "absolute";
WhiteOutDiv.style.filter = "alpha(opacity=" + currOpacity + ")"; // IE
WhiteOutDiv.style.opacity = currOpacity / 100; // Firefox, etc..
WhiteOutDiv.style.backgroundColor = "#ffffff";
WhiteOutDiv.style.top = "0px";
WhiteOutDiv.style.left = "0px";
WhiteOutDiv.innerHTML = " "
WhiteOutDiv.style.width = "100%";
Are you asking a question?
Don't be ridiculous, use .className
I've switched careers...
I'm NO LONGER a scientist,
but now a web developer...
It's not that black and white.
External CSS is fine when you have tight control over everything, but when you release your code into "the wild" it can make it more fragile.
I've had the CSS in external files get modified by 3rd parties, "breaking" my functions when I have used className.
I've had customers move to new sites and not porting over all their CSS files, "breaking" the functions I wrote which depended on className assignments.
I've had customers consolidate several CSS files into one and had inheritance rules break functions which relied on className
None of these problems would have happened if I had used the ".style" property instead.
I'd stick with .className, although you could use shorthand style:
At least 98% of internet users' DNA is identical to that of chimpanzees
I want to use className as it makes things easier for me to make changes later on.
You would think that using classNames would make it the more flexible approach, but I found that if I am creating components to be used by people who are primarily server side or DB developers that they have a poor to weak understanding of CSS (or of client side altogether).
Instead of making it easier for them to use, I am making it harder. They now have to learn yet another language, along with keeping up with the quirks and spotty support CSS has in different browsers.
I just wish there was a way to black box the approach to using JS with CSS classnames. Their current separation reminds me of the old programming days when the user had to edit the config file with notepad if they wanted to change how anything worked. A bit of the horrible user experience there.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)