CUTCODEDOWN
Minimalist Semantic Markup

Welcome Guest
Please Login or Register

If you have registered but not recieved your activation e-mail in a reasonable amount of time, or have issues with using the registration form, please use our Contact Form for assistance. Include both your username and the e-mail you tried to register with.

Author Topic: CSS Grid issues  (Read 3448 times)

Exodus_AU

  • Junior Member
  • *
  • Posts: 6
  • Karma: +0/-0
CSS Grid issues
« on: 10 Mar 2020, 01:54:51 am »
Hey,

Just started getting back into small time coding, could have whipped something up in bootcrap but whats the point...

I have made the following: http://mitwc.com.au/testing/

I have the following problems.
  • The icons, they are spaced on desktop (obviously because im using auto on the grid, how can i make it have no spacing by default? i tried grid-gap to no avail.. ill worry about responsiveness here later
  • The about us section and the Contact form is showing different widths and i cannot figure out how to make this even..

any help would be appreciated.

mmerlinn

  • Jr. Member
  • **
  • Posts: 77
  • Karma: +9/-0
  • Nutcake
Re: CSS Grid issues
« Reply #1 on: 10 Mar 2020, 02:13:16 am »
Without seeing your code, all we can do is waste our time playing a GUESSING game.
The soul purr pus of a spell cheque cur is two valley date hour ignore ants.

Exodus_AU

  • Junior Member
  • *
  • Posts: 6
  • Karma: +0/-0
Re: CSS Grid issues
« Reply #2 on: 10 Mar 2020, 02:36:12 am »
i shared the link to the live site where the code can be viewed?

GrumpyYoungMan

  • Hero Member
  • *****
  • Posts: 792
  • Karma: +8/-0
    • Grumpy Young Man
Re: CSS Grid issues
« Reply #3 on: 10 Mar 2020, 05:33:41 am »
i shared the link to the live site where the code can be viewed?
I found it's better to post the code - or use CodePen... ;)
Trying to learn a new trick to prove old dogs can learn new ones...

Total Novice have-a go Amateur Programmer - not sure that is the right thing to say... but trying to learn...

sunfighter

  • Global Moderator
  • Junior Member
  • *****
  • Posts: 17
  • Karma: +1/-0
Re: CSS Grid issues
« Reply #4 on: 10 Mar 2020, 12:35:34 pm »
Welcome to the forums Exodus_AU. Hope you find our service to be helpful.
I'd like to start by saying "Do not use CodePen" I hate the way I need to copy/paste to run the code.
Paste code here or give a link to live site. You did that and I love you for that.

Here's a great site for you to look at and use: https://www.caniuse.com/ It shows you that webkit stuff is not needed. The following CSS will give what you asked for about the buttons. If you want things done in flex or grid you should ask again.  ;D
Code: [Select]
<style>
.tiles {
  margin-top: 2em;
  padding-right: 35px;
  padding-left: 35px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tile {
    background: #8e9eab;
    background: linear-gradient(to right, #eef2f3, #8e9eab);
    box-shadow: 3px 4px 5px 0px rgba(0, 0, 0, 0.75);
    padding: 15px 15px 15px 15px;
    text-align: center;
    width: 170px;
    float: left;
    margin-right: 5px;
}
.tile .icon {
    font-size: 5em;
    margin-bottom: .15em;
}
</style>
width: 170px; in the tile class was used to show the right shadow.
I'll work on the second question and get back to you.
Curious that we spend more time congratulating people who have succeeded than encouraging people who have not. - Neil deGrasse Tyson

coothead

  • Sr. Member
  • ****
  • Posts: 391
  • Karma: +89/-0
  • I smile benignly
    • coothead's stuff ~ an eclectic collection
Re: CSS Grid issues
« Reply #5 on: 10 Mar 2020, 01:03:49 pm »
I'd like to start by saying "Do not use CodePen".
I hate the way I need to copy/paste to run the code.
Paste code here or give a link to live site.
You did that and I love you for that.

CodePen is similar  to  Marmite; either you love it  :) , or you hate it.  >:(

I have been moaned at on some forums for posting code and not using
CodePen and visa versa, I often get round this impasse by employing
both.  8)

I use CodePen to display in full page mode and [code] [ /code] to
display the code.


coothead
~ the original bald headed old fart ~

mmerlinn

  • Jr. Member
  • **
  • Posts: 77
  • Karma: +9/-0
  • Nutcake
Re: CSS Grid issues
« Reply #6 on: 10 Mar 2020, 08:44:59 pm »
i shared the link to the live site where the code can be viewed?

Sure, the code CAN be viewed there. However, if the code in that link EVER changes, NO ONE will be able to understand your original question nor any comments posted here PRIOR to your code changes.

Further, links disappear constantly, so how is anyone, say a year from now, having the same problem, ever going solve their problem if they CANNOT see your ORIGINAL problem and see HOW you solved it?
The soul purr pus of a spell cheque cur is two valley date hour ignore ants.

Jason Knight

  • Administrator
  • Hero Member
  • *****
  • Posts: 1054
  • Karma: +188/-1
    • CutCodeDown -- Minimalist Semantic Markup
Re: CSS Grid issues
« Reply #7 on: 10 Mar 2020, 10:43:43 pm »
On the whole, I prefer the live link over garbage like codepen... I mean pens are ok, but I'd prefer to see a live page.

We all look at things different I guess... and yeah, as @coothead mentioned, I've seen people bitch any way you do it. Some complain if it's a pen, some complain if you cut/paste, some complain if it's a live link... It's like FFS people, at least he gave us SOMETHING that has the complete picture.

That's more than what most people provide!

Now, that said...

There are a lot of issues with what you have, but let's start with what you asked about. I'd probably just set the inner containers to inline-block and the parent to display:flex. That really should be all that's needed for CSS apart from perhaps the alignment properties.

Though while we're here, let's talk about your page.

First off, you've got illegible low-contrast colors. The un-hovered menu items are likely invisible for a large chunk of the population, and that white on magenta is... dicey with such a thin-glyph font. Generally I dislike such fonts because as "pretty" as they might be to the artsy types, they tend to piss on accessibility from on-high. NexaLight, much like Raleway, is a really, REALLY bad choice for a font for screen media.

When it comes to color choices of background to foreground contrasts, I suggest always checking against an accessibility tool like the one at webaim.

https://webaim.org/resources/contrastchecker/

In general if you're using a system font at 1 system EM, you should treat normal AA as your minimum. If you use a normal webfont, AAA is your minimum. If you use a glyph with really, REALLY thin lines like nexalight or raleway, well... thanks to font smoothing and differences in rendering tech you should consider a 10:1 ratio as your minimum.

Sadly the WCAG standards were laid in stone before font smooting and webfonts were a thing. I should probably get off my arse and make my own tool that reflects the changes of the past decade and a half.

Now your markup... for the most part it's nice to see something clean and well formatted for a change. The problem is your general lack of semantics and/or incorrect semantics. What makes one word a grammatical <p>aragraph? What makes <label> and <input> grammatical paragraphs?

But let's work our way through top to bottom. It's what i do.

First thing that grabs my attention is the pointless X-UA <meta>. The entire point of even having that present is to make modern IE work like older ones, NOT the other way around which is why ie="edge" defeats the point of using it. The only reason to set that is if the domain has been "compatibility listed" to IE8 throught 10, (11 ignores it) and really if that compatibility mode is "needed", you've got something seriously broken in either your HTML or your CSS.

So get rid of that nonsense.

Next, you've got a stylesheet link, but what's it FOR? Where's your media="screen" since that seems to be your screen media target?

Good rule of thumb? If you see <link rel="stylesheet"> and it doesn't have a media="" on it, whoever wrote it doesn't know enough HTML. (yes folks who created, maintain, and promote "front-end frameworks", I'm talking about YOU!). I suggest setting media="screen,projection,tv" for maximum compatibility, even though HTML 5's increasingly useless validation throws a conniption fit about it. I swear, it's like the W3C and WhatWG are doing everything they can to drag us back to the worst of 1990's coding practices.

You want to say what it's for, so you're not sending screen layout to print, speech/aural, TTY, or some future type of device we've not even concieved of yet.

Likewise "site.css" is kind of vague, of course it's CSS for the site. I often prefer to use the media target as the name so you can tell what the sheets are for.

Now there's that script... to load font-awesome? Why would you do that? Font-awesome should NOT be reliant on JavaScript to function! That's just silly. Just find a commonly used CDN like the one on cloudflare, and use it.

Also, scripts inside <head> can block the render until that script loads, hence the term "blocking script". It is really recommended that well written scripts belong right before </body> and NOT inside your <head>.

In your head... in your heeheeaaahed, zombies, zombies, bees, bees

I see the telltales of prepping for a scriptless mobile menu, that's good. I'd suggest throwing HTML 5's semi-new "hidden" attribute on the input so that non-screen media UA's .. or at least any modern HTML 5 supporting ones.

NAV is a pretty pointless tag if you use headings properly... though you have content BEFORE your H1, so you're not using headings properly. Semantics first, layout second.

Likewise avoid using classes that are named the same as a psuedo-state. It's easy to get confused the difference between:

a.active
a:active

So try something else like "current".

Your "web banner" image does not appear to be content... as such it flat out doesn't belong in the markup. I also see no real reason for the extra DIV wrapping it. Background-image on .banner would make more sense.

Not sure you need div.banner-text either, but that depends a lot on how you're aligning things. Not sure why a "description text" would get "more emphasis" (what strong means) either... and again, what makes a "my cool button" anchor a "grammatical paragraph" -- what the <p> tag MEANS.

REmember, you should be choosing your semantic tags by MEANING, not what you want things to look like.

Your tile section seems equally non-semantic and burdened with "classes for nothing". I have the feeling you've fallen into the trap of slapping a class on anything and everything you want to style, and that's just bad practice that results in bloated markup. This APPEARS to be a list of items, we have tags for that. Again, not sure what makes those SINGLE WORDS be <p>aragraphs much less require "more emphasis", and really since every tag inside .tiles is getting the same class, NONE of them need classes. Even that "icon" class could probably be axed if you just leverage selectors properly.

Also I would assume those would someday be anchors? If so, that should be coded LONG before you start styling them.

... and don't let the know-nothings try to tell you that slopping a class on everything is somehow "faster" than using selectors in the CSS. 100% bullcookies. What's going to be faster for the browser? Using more markup that creates a larger pointered list of elements with classes on them, or handling CSS selectors that have been MORE than fast enough all the way back to IE 5 on a 486/66 running Windows 3.1?

There are a LOT of "experts" out there working for big places like Google and Pingdom who are utterly and completely full of manure in terms of what makes a page "faster". Ten times the markup and increasing the memory and processing overhead is NOT going to be faster guys!

When you have major sections, like your "about us", I suggest using an ID instead of a class. The unique identifier ends up handy if you want to add 'on page" navigation later on since they can also be hash targets.

Your DIV around the form is also a bit silly since <form> is a perfectly good block level container. Move the H3 inside the form, and add the PROPER semantics to your form since, well... where's your <fieldset>? Under HTML 4 STrict a block level container inside FORM was required for a reason, and whilst HTML 5 has pissed on strict from orbit, it's still proper semantics that your user inputs be in a fieldset... a semantic tag that would let you not waste a class on things.

... and whilst <footer> is allegedly semantic, with EVERY real UA treating them as a <div> and NOTHING more, I'd put a <hr> in there to properly mark that the footer content is not part of the H3 or H2 preceding it.

Now, I usually frown on HTML 5's new "structural" elements, but people seem to expect us to use them even if they're LITERALLY just DIV since no legitimate UA does anything special with them. With that in mind a more semantic version of your markup might read something like:

Code: [Select]
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8">
<meta
name="viewport"
content="width=device-width,height=device-height,initial-scale=1"
>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css"
integrity="sha256-+N4/V/SbAFiW1MPBCXnfnP9QSN3+Keu+NlB+0ev/YKQ="
crossorigin="anonymous"
media="screen,projection,tv"
><link
rel="stylesheet"
href="screen.css"
media="screen,projection,tv"
>
<title>Testing</title>
</head><body>


<header id="top">

<input type="checkbox" id="toggle_mainMenu" hidden>
<label for="toggle_mainMenu"></label>

<div>

<h1>
Header<br>
<small>Tagline</small>
</h1>
<a href="#" class="ctaButton">My Cool Button</a>

</div>

<nav>

<ul id="mainMenu">
<li><a href="#" class="current">Home</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Contact Us</a></li>
</ul>

<ul class="tiles">
<li>
<a href="#">
<i class="far fa-lightbulb"></i>
Lights
</a>
</li><li>
<a href="#">
<i class="far fa-lightbulb"></i>
Lights
</a>
</li><li>
<a href="#">
<i class="far fa-lightbulb"></i>
Lights
</a>
</li><li>
<a href="#">
<i class="far fa-lightbulb"></i>
Lights
</a>
</li><li>
<a href="#">
<i class="far fa-lightbulb"></i>
Lights
</a>
</li><li>
<a href="#">
<i class="far fa-lightbulb"></i>
Lights
</a>
</li><li>
<a href="#">
<i class="far fa-lightbulb"></i>
Lights
</a>
</li>
</ul>

</nav>

</header>

<section id="aboutUs">
<h2>About Us</h2>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum
</p>
<!-- #aboutUs --></section>

<section id="contactUs">
<div>
<h2>Contact Us</h2>
<ul>
<li>Title</li>
<li>Message</li>
<li>email</li>
</ul>
</div>
<form action="" method="post">
<h3>Send us a message</h3>
<fieldset>
<label>
Your name<br>
<input type="text" name="name" required><br>
</label><label>
Email Address<br>
<input type="email" name="email" required><br>
</label><label>
Write your message<br>
<textarea name="message" cols="30" rows="7"></textarea><br>
</label>
<button>Send</button>
</fieldset>
</form>
<!-- #contactUs --></section>

<footer>
<hr>
&copy; 2020
</footer>

</body></html>

77% the code, more accessible, and provides more than enough hooks for all the style you were attempting to apply.

Heading to bed soon, but if I have time tomorrow I'll toss together a quick rewrite of what you have so far and a full breakdown/explanation you can learn from... since your CSS has a number of issues that would/should be cleaned up as well.

« Last Edit: 11 Mar 2020, 01:28:29 am by Jason Knight »
We are all, we are all, we are all FRIENDS! For today we're all brothers, tonight we're all friends. Our moment of peace in a war that never ends.

Exodus_AU

  • Junior Member
  • *
  • Posts: 6
  • Karma: +0/-0
Re: CSS Grid issues
« Reply #8 on: 11 Mar 2020, 01:36:05 am »
Thanks for the information.

I would like to start by saying I'm just getting back into this after a very long time so I want to thank you for providing such a breakdown.

OK I'm a bit confused by when to use Grid and when to use flex and assume I'll pick this up the further I head down the rabbit hole.

I very much agree on the menu items and have not given thought as to how I should change them, it has been annoying me heavily that they vanish into the page. WIP

I didn't give any thought to the contrasts as you mentioned. just liked the colors and tried to match the banner. Likewise with the Font, just liked it... no other reason its there :)


X-AU meta was unfortunatelty lack of experience... I am using VSCode and used the ! hotkey to generate the raw HTML tags which included this.

Last time I was coding was more back-end ASP.NET where the standard is to use site.css with bootcrap for front end development. Point taken :)

I love that you brought up font awesome, I originally loaded in a CDN and found some icons didn't work.. I registered on their site to get a personalised CDN and they provided the JavaScript with the instructions to load in head! I was perplexed by this and again, lack of experience ASSumed not to question them.

I have plans to make the menu responsive and have been reading your article on a CSS only menu as I'm sure you picked up on.

As for my overall markup and junky classes, just bad learning experience / practice from ASP.NET where the defaults are all bootstrap for UI.

I'm trying to get a handle on the front end development and didn't want to use that crap which unfortunately you see the pitfalls in my code.

I very much look forward to your CSS review if you find the time.

Kind Regards,
Exodus

Jason Knight

  • Administrator
  • Hero Member
  • *****
  • Posts: 1054
  • Karma: +188/-1
    • CutCodeDown -- Minimalist Semantic Markup
Re: CSS Grid issues
« Reply #9 on: 11 Mar 2020, 02:44:43 am »
OK I'm a bit confused by when to use Grid and when to use flex and assume I'll pick this up the further I head down the rabbit hole.
My rule of thumb is that if you care about IE10/earlier, you can't use either. If you care about IE11 you can use flex, and if IE doesn't matter, go for grid.

But, that "doesn't matter" is in relation to "graceful degradation" --- if it doesn't work BUT the page is still usable in those browsers -- even if it's not the layout you want -- CLOSE ENOUGH. We have to stop bending over backwards to 100% support decade+ old browsers. If columnar layout drops to one column, or they don't get rounded corners and shadows, OH WELL. Those are NOT mission critical for what's really important: delivering content to users.

I very much agree on the menu items and have not given thought as to how I should change them, it has been annoying me heavily that they vanish into the page. WIP

I'd probably given them a white or transparent white background with a white text-shadow. Would let them stand out when over things further down the page. The use of text-shadow could also alleviate the need to turn down the brightness of that magenta.

There are ways...

X-AU meta was unfortunatelty lack of experience... I am using VSCode and used the ! hotkey to generate the raw HTML tags which included this.
One of the reasons I say it's foolhardy to use Microsoft products for anything web devleopment related. I mean it's a fine editor, but on the whole any editor that "does things for you" is probably gonna do it wrong. It's a concept a LOT of folks -- WYSIWYG editor users, "site builder" users, e-macs fans -- won't even listen to.

Probably why with my choice of editor I turn it all off. Hell, I'd use notepad if the search/replace were a bit more robust, it did proper tab to space and back conversions, and didn't choke on utf-8.

I love that you brought up font awesome, I originally loaded in a CDN and found some icons didn't work..
99% of the time that happens, the CDN is feeding you an old version. Version 4 -- which the current "icon lookup" part of their site points at, is still relatively new and a LOT of places are still feeding the old files.

The one I use:

Code: [Select]
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css"
integrity="sha256-+N4/V/SbAFiW1MPBCXnfnP9QSN3+Keu+NlB+0ev/YKQ="
crossorigin="anonymous"
media="screen,projection,tv"
>

Seems to be good for now. Includes all the checks needed should you need it to work under the CSP (content security policy)

That "registering" with them gets you that horrifying mess of JavaScript? Yikes. But like anything else, over time you get "hired help" who probably shouldn't be trying to help yet.

lack of experience ASSumed not to question them.
Question EVERYTHING, even what I tell you. There are a LOT of fly-by-night frauds out there claiming to be experts. Most of them couldn't code their way out of a piss soaked paper bag with a hole in the bottom.

As for my overall markup and junky classes, just bad learning experience / practice from ASP.NET where the defaults are all bootstrap for UI.
If you're coming from ASP.net, I'm actually surprised your code is that clean. Where's the 192k base64 encoded "token" meta in the markup? :D

It is all a big learning process, but honestly it's not THAT complex once certain basic concepts click. That's the problem though, for a lot of people -- even some big names in this industry -- it never clicks. End result is their using JS to do HTML and CSS' job, JS where it isn't needed, non-semantic markup, extra markup where unneccessary, etc, etc, etc.

If it feels like it's getting too complicated, you're overthinking it or you need to dial back the bling and "keep it in your pants" on the fancy stuff.

Remember, Apple revolutionized web design by ripping it all out... and then pissed their own bed in recent years by sleazing it all back in. Then they wonder why they're not meeting profit projections.
We are all, we are all, we are all FRIENDS! For today we're all brothers, tonight we're all friends. Our moment of peace in a war that never ends.

Jason Knight

  • Administrator
  • Hero Member
  • *****
  • Posts: 1054
  • Karma: +188/-1
    • CutCodeDown -- Minimalist Semantic Markup
Re: CSS Grid issues
« Reply #10 on: 11 Mar 2020, 11:00:27 am »
Alright, here is that rewrite up and running with some CSS and some other optimizations.

https://cutcodedown.com/for_others/Exodus_AU/testing1/testing.html

As with all my examples the directory is wide open for easy access to the gooey bits and pieces.

https://cutcodedown.com/for_others/Exodus_AU/testing1/

Your original was 8.5k for the HTML and CSS combined, my rewrite is 8.28k, you know what that means? Your original wasn't THAT bad. I mean sure, around 1k of mine is that I make it responsive, but still your original's biggest problems were a few outdated attributes and a lack of proper semantics.

I also took some stylistic liberties. with the "lights" buttons centered at a fixed size, it didn't look right to me, so I used flex to make them expand to fit. This let's us set flex-wrap so that when the page is too small they will, well, wrap.

For a font I went with Avante Garde, which is very similar to Nexa in overall shape, it just has wider bars/slabs, better kerning, and a lower letter-spacing. Said spacing is almost too low, so I set a letter-spacing to bring it up a bit more legibile. That's a handy sneaky trick with some fonts as you can often take hard to read fonts and improve them just by moving the letters apart a hair. Ends up looking like a whole new font! In some cases it can even make serif fonts -- which are usually too detailed for screen media -- look good. Shout out to my buddy Alex for showing me that little trick with plain-jane "times new roman".

Naturally I darkened the magenta, but not all the way as text-shadow fixes up the other issues.

Before I explain my CSS, I'd like to briefly review the issues with yours and a couple other changes.

First off you were using OTF with no style/weight declarations. That's actually not fully/properly functional and could have been contributing to the rendering issues. The proper formatS (yes, plural) to use nowadays are WOFF and WOFF2. Pretty much IE9 and newer supports at least WOFF as does every modern browser, and WOFF2 support is pretty complete across any browser release of the past six years. We want both formats, since WOFF2 is basically just WOFF with internal file compression.

Your background image was WAY too massive for its own good. At half a megabyte it was twice the size most conventional pages -- HTMl + all CSS + all Scripts + all images -- should be. It was in fact three times the resolution of a 4k display... It also has low colour depth which makes it a candidate for 8 bit colourspace, hence I dropped it to 1920x1260 (since even at 4k it's only half the screen width) with 256 colours, and badda-boom badda-bing, it's now 42k instead of half a meg.

I like to do my image optimization early, so I don't forget later.

The so-called "universal reset" of * { margin:0; padding:0; } is cute for testing, but it can wreak havoc with consistency of appearance of form elements cross browser. That's why I suggest using a proper "reset". Some resets are so big -- like Eric Meyer's "reset Reloaded"-- that they give resets a bad name as they waste time changing things that aren't inconsistent cross browser. Others like the universal causes problems. The one I use is a nice safe middle ground.

Code: [Select]
/* null margins and padding to give good cross-browser baseline */
html,body,address,blockquote,div,
form,fieldset,caption,
h1,h2,h3,h4,h5,h6,
hr,ul,li,ol,ul,dl,dt,dd,
table,tr,td,th,p,img {
margin:0;
padding:0;
}

img, fieldset {
border:none;
}

That only nabs what you NEED to hit. At a quarter K it's well worth it for the consistency.

You set overflow-x to hidden which is usually a bad idea. If you "need" to do that, there's something wrong with your layout.

On your .active class you repeated the same padding that the "a" setting should have hit. You do that a few times, and it's something to avoid. If you have a perfectly good parent tag already defined, only declare what changes on the pseudo and classes.

Trying to make the banner area a grid is kind-of faulty. I mean it's not a horrible idea, but really that's a background image, pad your content off of it.

text-decoration-color is fairly new and poorly supported, so I'd suggest using a border instead. Border is actually nicer in some ways as you can control the amount of space between the text and the border with padding.

You declare a LOT of things in pixels, and that's really not good. Particularly if you are using dynamic fonts with pixel paddings, or dynamic fonts with pixel metric media queries.

Pixels were NEVER the correct measurement for sizing things online, and even less so now that we have support for vector formats like SVG, fonts for icons, and so forth. The "EM" measurement should be your preferred tool for everything other than "razor thin borders" since it dynamically scales to the user choice -- that way they don't have to dick around zooming all teh time -- instead of being a "fixed measurement". When possible try to declare all your fonts, padding, margins, widths, heights, and media queries in EM.

Finally you have a few manual declarations that should simply be condensed. See something simple like:

Code: [Select]
margin-top: 5em;
padding: 35px 35px 35px 35px;
margin-right: auto;
margin-left: auto;

That could be stated as:

Code: [Select]
margin:5em auto 0;
padding:35px;

The condensed properties are your friend... and remember it's clockwise, and if a value is missing it uses the one from the opposite side.

Ok, gimme a bit to write up a CSS breakdown/explanation. I'll likely have time for that some time after lunch, so around 2 or 3 EST.
We are all, we are all, we are all FRIENDS! For today we're all brothers, tonight we're all friends. Our moment of peace in a war that never ends.

Jason Knight

  • Administrator
  • Hero Member
  • *****
  • Posts: 1054
  • Karma: +188/-1
    • CutCodeDown -- Minimalist Semantic Markup
Re: CSS Grid issues
« Reply #11 on: 11 Mar 2020, 11:35:54 pm »
Sorry for the delay, old man ended up needing his afternoon nap. :D

Let's break down the CSS. Follow the bouncing ball at:

https://cutcodedown.com/for_others/Exodus_AU/testing1/screen.css

First up we have modern webfont declarations. See how both of them use the same font-family name, and explicity declare weight and style? That's how it's SUPPOSED to be used. It's shocking how many places -- even ones I use to handle format conversions like Font Squirrel, or good documentation like MDN -- fail to mention that little detail.

As I mentioned in the last post, we only really need woff and woff2 at this point. OTF is old outdated IE 5 nonsense, with the more modern formats being both smaller, and tend to render better on non-Microsoft platforms.

Next is that reset... just big enough to reset what NEEDS to be reset without screwing over elements that have 'issues', whilst just small enough to not piss all over the place.

I set the border-box box-model on all elements because it's just easier to work with. For all the years of asshats running their mouths about the "standards box model" and how IE's "broken box model" was bad, now we have a means of actually triggering said "border and padding are inside width" behavior, and those same asshats run around singing its praises. This is why I have a lot of disgust with fellow developers. I've been saying the "incorrect" IE way was better for 20+ years...

Now we can use it with impunity.

I hide HR on pages because they exist as a semantic element, marking a change in topci/subject basically saying "this text is not part of the headings before it". (which is why HTML 5's "footer" is a pointless redundancy). IT DOES NOT MEAN DRAW A LINE ACROSS THE SCREEN! Most people hear "horizontal rule" and think drawing a line with a ruler, and not a grammatical or structural RULE.

Kind of like vertical breaks -- or as some mouth breathers now call it a "pipe".

The first media query fixes some older iOS and Windows Mobile devices that pre-date the viewport META. If the -webkit- version is sent to desktop Safari it can break the ability to zoom (but not on mobile, way to herp that derp there Apple!) but few desktop users would make their window narrower than 480px, and every device that "needs' this fix is smaller than that.

At this point said devices are probably dead and buried in terms of userbase, but it's 105 bytes of code, so no harm in including it.

Remember, when I'm talking about minimalism I don't mean byte obsession.

I always set 100% height on html and body just because some layouts need it, sometimes backgrounds get choppped if you don't set it, and child elements cannot set % heights if the parent doesn't have a height on it.

From here out I'm going to summarize by selector. When making the primary layout before I write the big media queries, I like to start with desktop then pare it down. A lot of people will tell you to start with mobile and work your way up, but I find that approach utterly back-assward. We can target any mobile we care about with media queries... you know what we can't target with media queries? Old desktops, that's what!

body, button, input, table, textarea, select -- This nabs the elements that don't inherit from body for our primary font properties. As well as body itself. I use a 1.5em line-height on flow text as it aids legibility the longer your paragraphs get and/or wider the screen is.

body -- upping the letter spacing makes Avante Garde look more like nexa, and improves overall legibility. I've always liked this font as it's got that same style but without the rail thin glyphs... but the low default letter spacing needs some help, so help we provide.

for normal/16px/vga/100%/96dpi/"windows vista+ small" / pickAdamnedNameAlready users, 0.0625em will be 1px. For large/20px/8514/125%/120dpi/"windows vista+ medium" / pickAhuffingName already users like myself it's 1.25px... and on my 4k media center it's 2px. Aren't EM fun to work with?

#toggle_mainMenu -- you know what this is. IE doesn't obey label clicks if the input is "hidden", so we set display block to show it, then sneakily hide it off screen.

#top -- I called this <header> #top so if you want to add a "back to top" link later, it's just <a href="#top"> and you're off and running. Bottom margin pushes the content area off of it.

#top > div your "webBanner" area. Doesn't really need a class or ID since it's the only div that's a direct child of #top. The cute trick here is that I use padding to push the text off the image, then set the background-size to auto-adjust width whilst filling 100% of the DIV container.

h1 -- as there should only be one H1 if we use the 'classic' structural rules, no reason for this to have a class or ID. The padding actually sets the large height of the banner area, which we'll be able to exploit to shrink it later in the media queries. I also lower the line-height since this isn't flow text.

h1 small -- the display:block actually makes it obey its own line-height instead of its parent -- the <br> in the markup mostly being there for non-CSS users. SMALL does not mean "this text should be displayed smaller", it means "this text would be smaller for gramamtical reasons in a professionally written document, such as for de-emphasis"... a tagline under a heading fits that description as it's a subtext of the numbered heading. We explicity restate the line-height because Chakra based Edge is an idiot. Thankfully with Chromium based edge slowly replacing the old Edge, we won't have to deal with that derpitude forever!

#mainMenu -- kill the bullets, fix it on the screen. Not complicated.

#mainMenu li -- inline-block puts them all on one line (duh), and basically strips LI of formatting. Given the plethora of rendering issues that can arise when trying to style LI, it's often better to just set it to inline and target the child elements (anchors) instead.

#mainMenu a -- inline-block so they can accept padding, margin to space them apart, coloration. I added a translucent white background so when you scroll, they're still legible.

#mainMenu a,
.ctaButton
-- both of these share these same basic styles, so group their selectors to reduce the overall code, AND to make it easy to change both of them at the same time. Also helps to set up any transitions we might want.

#mainMenu a:focus,
#mainMenu a:hover,
#mainMenu a.current,
.ctaButton,
#contactUs > div,
#contactUs button:hover
-- ditto, these all get the same colouration, so set them together. This is why "mixins" and other such CSS pre-processor crap just reeks of being for people who don't know how to use CSS

#mainMenu a:focus,
#mainMenu a:hover,
.ctaButton:focus,
.ctaButton:hover
-- for hover on these elements I decided to add a scale transform to enlarge them, which is animated thanks to the transition declared on the anchors. When setting hover ALSO set your :focus so that people using keyboard navigation aren't left out in the cold.

.ctaButton -- gets some style that isn't in common with the other groupings, like larger text and some bottom margin.

.ctaButton:focus,
.ctaButton:hover
-- likewise it gets a different background color on hover, since its default state looks like the menu hover state.

.tiles -- these looked like a list of anchors, so I coded them as such. Kill the bullets, set up flex, turn on wrapping for flex if things don't fit, and set an alignment just in case.

.tiles li -- the display:inline is for browsers that don't support flex and again the "issues" I mentioned with styling LI before. Remember that the condensed flex property is "grow, shrink, basis"... in this case we want auto width, it can grow to fit the available space (1), but not shrink below its content size (0)

.tiles a -- the block setting makes it fill the parent container. The min-width makes sure that they stay visible and wrap as needed. I chose 10em as that's typically the maximum text width I'd expect with those "lights" once you have more text inside them. Adjust as necessary. From there it's just padidng, margin, and alignment. The 1px bottom margin is just so that when it word-wraps there's a small border created by the box-shadow.

... and again notice how I'm doing almost everything in EM. The fractional pixel that 0.625em would create on that margin-bottom looked like ass, so that got 1px. One of those rare exceptions and why no "good practice" rule should be inviolate.

.tiles i -- again they don't need that "icon" class, they're the only italic tags inside these tiles, and it seems unlikely you'd be using book or document titles (the grammatical/semantic reason to use <i> when not <cite>ing said source) inside these "tiles".

body > section -- our main content "sections" can all easily be grabbed without throwing extra classes at things. You might be starting to see a trend in my thinking. The > says "only those that are direct children of" so you can use sections inside sections without this rule applying. The mix of 90% width with a max-width gives us a nice accessible limit, but again nothing you would be unfamiliar with. I tweaked the box-shadow so that there's 0.25em faint hairline at the top to make it clearer the start of the sections, whilst maintaining a nice bottom shadow.

Oh, and when you declare box-shadow, you can omit the "growth" number if it's going to be zero. Hence:

box-shadow:0 0.25em 0.75em 0 rgba(0,0,0,0.2);

and

box-shadow:0 0.25em 0.75em rgba(0,0,0,0.2);

Are functionally identical.

h2 -- I set these to inline block so they shrink to their content. Since a H2 is usually sibling to block-level elements (p, ul, ol, pre, form etc) and not inline / phrase level ones, this works well. This way we can use border-bottom instead of text-underline, since text-underline-color has spotty/unreliable support and doesn't even exist on Microsoft browsers (last I checked)

#aboutUs p -- enalrge the text to match what you were doing. I'm not wild about it that big, but it's not horrible.

#contactUs -- use flex to make the equal height columns. This way it at least has a chance at working in IE11. Again, set up wrapping just in case.

#contactUs > div -- that first level DIV we don't want to grow or shrink, so 0 0 on that. This allows the form to grow to fill the most space.

I do not set a bottom padding because flex elements compact out bottom padding and margins when possible to try and "make the most room" for mobile. The workaround for this I use:

#contactUs:after -- Just stuffs an element in there to make the gap. Normally you wouldn't say "width:100%" on a block level container, but as we're inside a flex we have to, otherwise it would ride up next to the form. Hence this too gets flex:0 0 auto;

#contactUs h2,
#contactUs h3
-- again these get the same basic values, so group their selectors.

#contactUs ul -- strip bullets, pad, yawn.

#contactUs Form -- this we want to grow to fill, but not shrink smaller than its contents allow for, hence flex:1 0 auto; I pad the top 1.5em to match the padding on the sibling DIV, making our H2 and H3 line up with each-other.

#contactUs input,
#contactUs textarea
-- again, shared style, and since we set box-sizing:border-box on everything, the padding and border are inside the width not around it... making it easy for us to make them grow to the available width. I gave them a bit of a style tweak whilst here.

#contactUs input:focus,
#contactUs textarea:focus
-- I turn off the default outline because Chromium/Blink based browsers do a SQUARE outline even if the element has rounded corners... so instead I apply a pretty box-shadow much akin to Safari's default focus behavior, just an off-magenta to match the layout instead of blue.


#contactUs button -- again, full width, padded, font-size... you know what this is. The hover state shared with the main menu becasue it's declared with a pseudo-class will override our background declaration here.

body > footer -- remember sections can have header and footer too, so a simple immediate child combinator works just like it did for <section>. Pad it, center content, color -- you know what all that does.

... and that's the base desktop layout! I did some of the groundwork for responsive layout as well, so let's summarize that by media query. Again note that since we're using dynamic fonts, our queries should also be in EM.

(max-width:85em) -- having just one tile drop and become full width looks silly, so if we set the min-width to 25% it will reduce it to a mix of 4 and 3, which looks far better. Depending on how many of these "tiles" you have in production you may end up adjusting this query width.

(max-width:70em) -- Changing the padding for the h1 and the DIV to be based on VW -- viewport width -- we're able to make it start scaling down smaller as the display shrinks, without it becoming a massive mess on displays over 1080p.

(max-width:66em) -- at this size it just helps to shrink and remove padding to better use the dwindling screen space, improving the user expierience. Likewise that massive default H2 size gets dropped a wee bit.

(max-width:42em) -- Shrink the banner image spacing even further, and lower the H1 padding to the smallest that still looks good. Likewise the fixed menu just looks better centered down this small, we kill the flex layout on #contactUs so the two sections are reduced to one column, and we shrink that oversized #aboutUs p for more comfortable reading on smaller displays.

... and that in a nutshell is how I'd have gone about what you have so far.

I know this is all a lot to take in, so study, try it, play with it, and come back with questions when you're ready.

We are all, we are all, we are all FRIENDS! For today we're all brothers, tonight we're all friends. Our moment of peace in a war that never ends.

Exodus_AU

  • Junior Member
  • *
  • Posts: 6
  • Karma: +0/-0
Re: CSS Grid issues
« Reply #12 on: 20 Mar 2020, 06:29:51 pm »
Sorry for the delay, what a crazy busy few week!

Thanks so much for the breakdown.

I didn't even realise how much I was interchanging between em's and px's until you mention :/ derp...

Thanks for exlpaining the fonts, didn't realise i could give them the same font-family and assign the weight to differentiate.

Few questions for you.
Quote
#toggle_mainMenu -- you know what this is. IE doesn't obey label clicks if the input is "hidden", so we set display block to show it, then sneakily hide it off screen.
I thought it was bad practice (appears malicious) to hide an element off of the viewport and that this may have negative impact on seo etc? Is this just nonsense that i read on a stupid article?

Quote
(max-width:85em) -- having just one tile drop and become full width looks silly, so if we set the min-width to 25% it will reduce it to a mix of 4 and 3, which looks far better. Depending on how many of these "tiles" you have in production you may end up adjusting this query width.
If i keep the tiles the same quantity however added different length text, is this the adjustment i would need to make to keep the tiles all lined up when the collapse?

Ive added an example of this on my test site: http://mitwc.com.au/testing

Mate, I want to thank you for all the time you have given me.

I am still playing (mainly with the flex components) to understand the impact of changing values like flex: 1 0 auto

Next I will be adding a Modal to the anchor tile tags from your article you wrote. Will keep you updated on that progress as i get there :)

Thanks again!

Jason Knight

  • Administrator
  • Hero Member
  • *****
  • Posts: 1054
  • Karma: +188/-1
    • CutCodeDown -- Minimalist Semantic Markup
Re: CSS Grid issues
« Reply #13 on: 21 Mar 2020, 01:20:14 am »
Thanks for exlpaining the fonts, didn't realise i could give them the same font-family and assign the weight to differentiate.
Few people do... when it's right there in the spec. Specific fonts often have their own pre-drawn versions, and don't look as good when you "let the engine do it", hence the mechanism for specifying different weights and styles that way.

Almost all windows system fonts work this way, if you look at the ACTUAL contents of the fonts directory you'll see that even humble arial has multiple font files for multiple weights, style,s, and all the combinations of the two... and yet if you look in the system fonts list you'll only see Arial and Arial Black -- and that's because the over-bold that is black doesn't fit into a normal font-weight stack.

I thought it was bad practice (appears malicious) to hide an element off of the viewport and that this may have negative impact on seo etc? Is this just nonsense that i read on a stupid article?
Probably just nonsense. Display:none is far more likely to cause SEO issues, but in this case the only penalty any search engine Should apply is to ignore the element. That's fine, it's not content so what do we care.

As a rule of thumb, search engines shouldn't give a flying purple fish what your style is. What they SHOULD be caring about is your text content, and the structure / meanings provided by the semantic use of markup. That SHOULD be the be-all end-all of the topic. BUT...

Thanks to black hat SEO dirtbags constantly trying to game the system, they started looking into the style about 17-18 years ago,  Specifically a technique called "content cloaking" where text was hidden somehow. To that end they started applying SOME of the style to elements to test for this, specifically ignoring the existence of any text that was display:none, visibility:hidden, or that had a color set the same as the background-color.

Problem with this is how does one then implement dropdown menus that search engines don't ignore? Position:absolute with off-screen positioning was the obvious answer... but that too was soon targeted as the SEO dirtbags abused it. Finally search engines -- or at least Google -- compromised and said that if you position it off screen the text itself will not be indexed, but it will still spider any links present and use the associated text of those anchors.

But overall the only real penalty any of these bring to the table is that the text content of such hidden elements are ignored.

I'd also point out that since INPUT is a "void" element, its presence and content would/should NEVER be used as part of a search ranking in the first place. The LABEL on the other hand...

Worst case, apart from being ignored there are no search penalties for this; though I've heard a lot of people flap their arse-cheeks in the wind about it. If this were in fact a thing 99%+ of all dropdown menus and 100% of all mobile / hamburger menus would get you smacked by the search engines. That clearly is NOT happening as if it did, there would be a huge outcry.

If i keep the tiles the same quantity however added different length text, is this the adjustment i would need to make to keep the tiles all lined up when the collapse?
That width tweak to prevent "one on its own" is something you'd have to adjust to meet the content, though the overall wrapping behavior once you're down below that is completely automated. It's just one spot that it's nice to adjust for.

Some things just can't be trusted to automate on their own properly, so changes to things like the menu do eventually -- no matter how well planned the layout -- end up having to be tweaked.

It's part of why if you read my progressive enhancement article's page 3:

https://cutcodedown.com/article/progressive_enhancement_part3

I talk about starting out at a desktop resolution, then resizing the display until it breaks. I figure out where it broke in EM width (pixels / 16 if at "normal" font size,  / 20 for "large font" users like myself,  Divided by 32 on my 4k media center), toss 5% rounded down to the nearest half EM as a bit of "wiggle room" to account for possible differences in font-family or font rendering/kerning, and use that as my media query break-point.

It's the fastest and easiest way to make sure all devices get the best layout for them. Take the desktop resolution, shrink the window until it breaks, add a query to fix what broke. shrink the window until it breaks, add a query to fix what broke. shrink the window until it breaks, add a query to fix what broke. Over and over again until you're down to 256px / 16em (if at normal system font scaling) the smallest one should really worry about in 2020 for display resolution. We [ii]used[/i] to go down to 192px, but these days there's no real point going that small.

I am still playing (mainly with the flex components) to understand the impact of changing values like flex: 1 0 auto
It's one of the things I don't like about flex, is that it uses 0 and 1 for on/off making it cryptic compared to other things in CSS where they use names. If they had simply said that "off" was saying nothing, and using "shrink" and "grow" instead of 0/1 0/1 would have been far far clearer.

Even though I KNOW it's "flex-shrink, flex-grow, flex-basis" as the order of the condensed "flex" properly, I STILL occasionally have to refresh my memory on that.

If instead of

flex:1 0 auto;

It had been:

flex:grow auto;

or:

flex:1 1 2em;

it was

flex:grow shrink 2em;

I think it would have been a lot easier for those just learning it to understand. But that's not how they chose to do it. In that way I think that the CSS3 grid layout module is better written and crafted as I find it easier to understand and far less cryptic... but grid sucks at doing anything you want to dynamically wrap or stack compared to flex. Sometimes that inflexibility is a blessing, sometimes it's not. It's why unlike a lot of dev's out there I don't go "flex or nothing, screw grid" or "grid or nothing, screw flex".

It's a problem this industry has as a whole, insisting on using the wrong tool for the wrong job. In regular programming you've got objects for nothing because "rawrz teh functions are teh evilz", or convoluted functions because "Objects are hard" (they aren't!). In HTML we have people who insist on presentational classes or presentational markup because "but the CSS is hard" or "it's more work" (it isn't, it's usually less work, see the derpitude that are frameworks that just make things harder by doing it ALL WRONG!). In HTML/CSS these days we have people going "now that we have flex there is no reason to ever use floats" or "floats aren't as versatile". Yeah, sure, of course. Call me when I can do shape-outside:ellipse on a flex child.

Simply put most people seem to only want to learn one way of doing things, then try and planket apply that one way to everything. Whilst in some cases -- like obeying the reason HTML exists and what it's for -- this makes perfect sense... well, in other cases all you're doing is running around with a hammer in one hand and a bag of screws in the other, and calling the hammer a "flathead screwdriver". Whilst you CAN drive a screw with a hammer, that doesn't make it a good idea.

Right tool for the right job, don't throw all the specialty tools out of your box just because you got a multitool. You'll find it kind of sucks when it's time to peen a pin, or tighten a bolt to a specific torque

But no, we have people out there -- ESPECIALLY career educators and students -- who insist that one specific way -- like flex -- is the be-all end-all answer to every problem. It's shortsighted, arrogant, and ignorant... and when you call them on it? They spew all the typical propaganda based nonsense that brainwashed them into thinking that way in the first place.

Basically, a mix of the 7 classic propaganda techniques riddled with fallacies, and a bunch of Lame excuses for not being a web professional.

Identifying when that is the case on "advice" you are given is an essential skill these days, given the sheer volume of snake oil peddlers out there, much less those who simply want to believe whatever lie they are peddled simply because it's soft, soothing, and exactly what they want to hear.

The truth is often harsh, brutal, and the last thing anyone wants to hear. Advocating for the truth is therefor often controversial, confrontational, and it's why the rank and file are often suckered in by the first good bullshit story they come across.

Hence how places like Sitepoint continues to sell books despite their authors clearly knowing jack about ****, how web rot scammers like W3Schools continues to have advocates and users despite being riddled with inaccuracies, omissions, and just plain bad practices, and how many "career educators" continue to be "influential" far past their expiration date... when in point of fact more often than not they've got less legitimacy than Amway, Mary Kay, Goop, Mercola, or the dirtbag calling himself an Avocado.

There's a reason a lot of businesses who deal in high volume software turnaround treat their new hire's first few months as a crash course in how things REALLY work, having to deprogram all the BS that was packed into their heads by alleged "educators". A situation only exacerbated by the fact that so many places now blindly believe all the bald faced LIES about frameworks, in the process screwing their employees, their products, and their customers.

Sorry there, didn't mean to rant, but it's stuff you really should be aware of. Web development as an industry has serious problems, mostly relating to truth and honesty. Most of the people I've dealt with freelance consulting the past decade I wouldn't trust to hold my beer for a minute.
We are all, we are all, we are all FRIENDS! For today we're all brothers, tonight we're all friends. Our moment of peace in a war that never ends.

Exodus_AU

  • Junior Member
  • *
  • Posts: 6
  • Karma: +0/-0
Re: CSS Grid issues
« Reply #14 on: 21 Mar 2020, 05:51:03 am »
No i 100% agree, I have been there with frameworks like BS (coming from ASP.NET back end).. It's how i had to learn.. It's making it much harder now to unlearn bad practice to come over to core standards.

On that note, how important is having multitude of spew around favicons? I started googling requirements on it and ended up stumbling upon a mess of:
Code: [Select]
        <link rel="shortcut icon" href="/favicon.ico">
<link rel="icon" sizes="16x16 32x32 64x64" href="/favicon.ico">
<link rel="icon" type="image/png" sizes="196x196" href="/favicon-192.png">
<link rel="icon" type="image/png" sizes="160x160" href="/favicon-160.png">
<link rel="icon" type="image/png" sizes="96x96" href="/favicon-96.png">
<link rel="icon" type="image/png" sizes="64x64" href="/favicon-64.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16.png">
<link rel="apple-touch-icon" href="/favicon-57.png">
<link rel="apple-touch-icon" sizes="114x114" href="/favicon-114.png">
<link rel="apple-touch-icon" sizes="72x72" href="/favicon-72.png">
<link rel="apple-touch-icon" sizes="144x144" href="/favicon-144.png">
<link rel="apple-touch-icon" sizes="60x60" href="/favicon-60.png">
<link rel="apple-touch-icon" sizes="120x120" href="/favicon-120.png">
<link rel="apple-touch-icon" sizes="76x76" href="/favicon-76.png">
<link rel="apple-touch-icon" sizes="152x152" href="/favicon-152.png">
<link rel="apple-touch-icon" sizes="180x180" href="/favicon-180.png">
<meta name="msapplication-TileColor" content="#FFFFFF">
<meta name="msapplication-TileImage" content="/favicon-144.png">
<meta name="msapplication-config" content="/browserconfig.xml">
or similar generators doing this: https://realfavicongenerator.net/

this is surely not needed?

 

SMF spam blocked by CleanTalk

Advertisement