How do you make this look so easy I even understood the code which I'm not used to without staring at it more.
Again something I told you and your co-workers in our zoom conference. Formatting and minimalism.
The less code you use, the less there is to break. The less code you use, the less code there is for others to digest. The less code you use, the easier it is to maintain.
Aka the opposite of modern practices and everything "hot and trendy" right now like these dumbass frameworks... where they start you out with more code than you should have before you even write a single line, to vomit up as much if not more code than you'd write without them... that on top of the underlying language you're supposed to learn ends up saddling you with even more crap on top.
Likewise I try to follow the grammatical/structural reasoning that created HTML in the first place. If you follow the intent of the language, the purpose of the tags, and leverage the meanings, you get cleaner easier to follow code.
It's why I wince when I see mind-numbingly stupid trash like:
<div class="h1 text-red box-shadow-inset col-4-s">
doing the job of:
<h1>
Or bloated trash like:
<div class="tac p42">
<fieldset class="tal dib bge">
Where christmas only knows what the blazes any of those classes are even supposed to be/do.
HTML has structural rules we're supposed to follow, but people make up lame excuses to not do so and/or are never taught them in the first place. HTML and CSS are separate for a reason which is why 100% of the time <style> is utter garbage and 99% of the time if you need style="" you're doing something wrong. Presentational tags were deprecated to simplify the markup and make us write more accessibile code, and that's why idiocy like:
<div class="text-center align-center font-size-large color-red">
Completely misses the point of HTML, CSS, and is such utter garbage the people who get wood for that type of lunacy need to admit defeat and go back to writing the HTML 3.2 they so clearly seem to miss... because that is NO different than writing:
<center><font size="3" color="red">
In terms of functionality... the VERY FLIPPING THING we were told to stop doing way the fudge back on HTML 4 Strict.
That's why making stylesheets like this:
.w3-pale-blue,.w3-hover-pale-blue:hover{color:#000!important;background-color:#ddffff!important}
.w3-text-amber,.w3-hover-text-amber:hover{color:#ffc107!important}
.w3-text-aqua,.w3-hover-text-aqua:hover{color:#00ffff!important}
.w3-text-blue,.w3-hover-text-blue:hover{color:#2196F3!important}
.w3-text-light-blue,.w3-hover-text-light-blue:hover{color:#87CEEB!important}
.w3-text-brown,.w3-hover-text-brown:hover{color:#795548!important}
.w3-text-cyan,.w3-hover-text-cyan:hover{color:#00bcd4!important}
.w3-text-blue-grey,.w3-hover-text-blue-grey:hover,.w3-text-blue-gray,.w3-hover-text-blue-gray:hover{color:#607d8b!important}
.w3-text-green,.w3-hover-text-green:hover{color:#4CAF50!important}
.w3-text-light-green,.w3-hover-text-light-green:hover{color:#8bc34a!important}
.w3-text-indigo,.w3-hover-text-indigo:hover{color:#3f51b5!important}
.w3-text-khaki,.w3-hover-text-khaki:hover{color:#b4aa50!important}
.w3-text-lime,.w3-hover-text-lime:hover{color:#cddc39!important}
.w3-text-orange,.w3-hover-text-orange:hover{color:#ff9800!important}
.w3-text-deep-orange,.w3-hover-text-deep-orange:hover{color:#ff5722!important}
.w3-text-pink,.w3-hover-text-pink:hover{color:#e91e63!important}
.w3-text-purple,.w3-hover-text-purple:hover{color:#9c27b0!important}
.w3-text-deep-purple,.w3-hover-text-deep-purple:hover{color:#673ab7!important}
.w3-text-red,.w3-hover-text-red:hover{color:#f44336!important}
.w3-text-sand,.w3-hover-text-sand:hover{color:#fdf5e6!important}
.w3-text-teal,.w3-hover-text-teal:hover{color:#009688!important}
.w3-text-yellow,.w3-hover-text-yellow:hover{color:#d2be0e!important}
.w3-text-white,.w3-hover-text-white:hover{color:#fff!important}
.w3-text-black,.w3-hover-text-black:hover{color:#000!important}
So you can crap the style into the markup is a complete failure to grasp the most basic of HTML/CSS principles, and reeks of the same broken halfwitted mindset that led to the worst code of the mid to late '90's browser wars.
The same goes for slopping the same classes onto everything. If you've got a class/id on the parent container, and every like-child of the same tag is getting the same class,
NONE of them should have classes. That was a big problem with your original code is that you were putting in a bunch of classes you just don't need. There's sufficient code uniformity that adding those "classes for nothing" only makes it more confusing and harder to follow.
Hence the more minimalist approach focused on semantics and leveraging that semantics with selectors. There is a BALD FACED LIE making the rounds that such selector use is "slow" or that you should use this mind-numbingly derpy "BEM" class naming convention to make the "render" faster... where much like with the "Tables are teh evilz" whackjobs it's a BS claim... since if a 486/66 with 8 megs of RAM running IE 5 under windows 3.1 could handle it, they can have a quadruple helping of sierra tango foxtrot uniform when my flipping $80 cheap Chinese phone has four cores clocking in at 1.5ghz.
As I've said many the time the past decade, maybe if people stopped using 128k of markup to do 16k or less' job, 500k or more of CSS to do 48k or less' job, and 2 megabytes
or more of JavaScript on pages that
if they even warrant the PRESENCE of scripting likely don't need more than 64k of it, MAYBE these derpy concerns about "render time" wouldn't be an issue. Maybe the idiotic "pageloads are evil" that suckers people into using broken SPA's (Single Page Applications) wouldn't be a thing. MAYBE, just MAYBE if people would learn the underlying languages they'd realize that "throwing more code at it" in the form of extra tags, extra classes, and these dipshit frameworks
But note, whilst I promote minimalism, THAT DOES NOT MEAN BYTE OBSESSION!!! I cannot emphasize that enough, that they are not the same flipping thing!
Minimalism means using as few tags, classes, and id's as you can get away with,
WITHOUT sacrificing code clarity or creating excess bloat elsewhere.. It does not mean bean-counting every byte, using cryptic class/id names nobody can figure out, or sacrificing whitespace... well, at least on your development copy.
(and really if whitespace minification pays dividends in your HTML, something's wrong with the HTML)Saving a few bytes is NEVER worth compromising the ability to read and maintain the code. That's the difference between minimalism and byte-obsession.
(I should write a Medium article on that...)An example of byte obsession comes from about a decade and a half ago, in the form of "holy grail layout". It was based on the idea that putting content before sidebar stuff. That's a good idea in terms of both accessibility and search. It is, not arguing that. But the "holy grail" idea was that each of the columns should only need one DIV to keep the markup small. (something we can do easily today with FLEX)
Problem was at the time people would use 1k of fragile, hack-filled CSS to avoid adding one extra <div></div> in their markup. That is DUMB.
Oh noes, notz won extru DIV!!!It's why "Holy Grail" was a really good name for it, as people became so obsessed with a single goal they never questioned the sanity of it. Just like the various fictions about the Arthurian knights, and how the quest for the Grail was actually their undoing.If you need that extra container, or you really need that extra class, go ahead and add it. Just don't dive for it as the be-all end-all answer to every question!
That's really a problem development wide, is people choose certain programming techniques, and then like the proverbial man with a hammer assume that everything is a nail.
The only place that mentality pays off is in code formatting. The one area the code you posted is absolutely PERFECT. You put the tags on their own lines and indented them consistently. IT's the ONE place where everything actually is a nail.
Clean, clear, consistent code formatting can do more for code clarity, digestibility, and maintainability than any other factor. Consistency, more than anything else, is what's important.
There are many, MANY different code formatting styles, they're all valid so long as everyone working on a project agrees to use the same one. CONSISTENCY!!! It's only when styles get mixed-and-matched, when "style guides" are not established or followed, or when people just "make it up as they go" that problems arise.
Like I was just dealing with some PHP code that went something like this: (slightly changed to protect the guilty)
if($_SERVER['SERVER_ADDR']=='127.0.0.1'){require_once 'local.config.php';}else{require_once 'net.config.php'; }
Nothing "really" wrong with it, though a ternary operator would simplify things... but it's painful to read because they whitespace stripped it for NO good reason. All over the codebase of said system there is zero consistency of formatting or style. Much of it seems minified, some of it has endless blank lines for who knows what, it's a mess.
Just simply formatting it and adding a hair of whitespace:
if ($_SERVER['SERVER_ADDR'] == '127.0.0.1') {
require_once 'local.config.php';
} else {
require_once 'net.config.php';
}
Improves the code clarity many-fold... and if one takes the time to realize that require_once can be functionally applied...
require_once(
$_SERVER['SERVER_ADDR'] == '127.0.0.1' ?
'local.config.php' :
'net.config.php'
);
Is even clearer/simpler.
Even the best code can LOOK confusing if it's poorly formatted. That's why this:
#gallery{list-style : none; display : flex; flex-wrap : wrap; justify-content : center; max-width : 48em; margin:0 auto;}
Is hard to follow hard to understand garbage compared to:
#gallery {
list-style:none;
display:flex;
flex-wrap:wrap;
justify-content:center;
max-width:48em;
margin:0 auto;
}
A concept that seems lost on far, FAR too many developers out there.