News for hackers. Stuff that matters.
Re:Tailwind CSS v3.0 by seanwilson on Thursday December 09, 2021 @03:50PM (#29502750)
> The trick with CSS is to write semantic HTML and avoid div, span and css classes

This experiment has failed though. CSS isn't powerful enough to style HTML however you want without having to add a soup of extra divs and classes that are only there for styling. No large website today works otherwise.

HTML is still semantic when it contains styling markup (in the sense that a computer can read and understand the structured data from it) so I'm unclear what benefit is being missed out on. Whether you call a class "home-cta-subheading" or "text-center" so you can apply some styles doesn't make a difference to screen readers, browsers or search crawlers either.

Re:Tailwind CSS v3.0 by Toutouxc on Thursday December 09, 2021 @05:06PM (#29503624)
> CSS isn't powerful enough to style HTML however you want without having to add a soup of extra divs and classes that are only there for styling

Totally this. We say we've come a long way from using tables for layout, but for example you still can't use Flexbox without at least some non-semantic .stuff-container and .radio-with-label junk. Decoupled HTML and CSS have failed in the real world, outside of pet projects.

Re:Tailwind CSS v3.0 by nsonha on Friday December 10, 2021 @02:25AM (#29507342)
I think grid is that powerful
Re:Tailwind CSS v3.0 by z3t4 on Thursday December 09, 2021 @04:37PM (#29503281)
The example on the Tailwind front page is pretty good semantic wise. Here's my version:

    <figure>
        <img src="/sarah-dayan.jpg">
        
        <blockquote>“Tailwind CSS is the only framework that I've seen scale
        on large teams. It’s easy to customize, adapts to any design,
        and the build size is tiny.”</blockquote>
        
        <figcaption><b>Sarah Dayan</b>Staff Engineer, Algolia</figcaption>
    </figure>
Re:Tailwind CSS v3.0 by seanwilson on Thursday December 09, 2021 @05:17PM (#29503735)
Now without modifying the HTML, how would I get the author's name only to appear on the right of the author image with the other text underneath? And add a line break before the company name? And make the word "tiny" use a small font?

And if you need to modify the HTML, were the extra tags added 100% only for semantic reasons and not for presentation reasons?

Re:Tailwind CSS v3.0 by Kerrick on Thursday December 09, 2021 @07:37PM (#29505075)
It's possible if you substitute "without modifying the HTML" with "without modifying the HTML for styling purposes." That's because the HTML is adversely and unnecessarily bare-bones, missing semantic markup that the CSS could hook into if needed. Specifically:

- There must be a logical reason for wanting to make the word "tiny" use a small font, so that word is missing a tag that represents that prosaic intent. I've used <small>, but depending on how you'd verbalize the word "tiny" (which is what you're representing both with making it use a smaller font and with wrapping it in a semantic tag), you might also wish to use <em> or another tag.

- Similarly, there is missing semantic markup inside the <figcaption> for the person's name, job title and company. Those are semantically separate concepts for each other, but for some reason the example HTML was written without semantically differentiating them. This is much like trying to represent two paragraphs of prose with just a couple newlines, rather than actually wrapping each in a <p> tag. To fix this error, I've added tags as necessary to implement the semantic hCard microformat -- independently of styling.

- I've also added the recommended attributes to the image tag, because it was missing. (And for the sake of the Codepen, I replaced the image's src with a placeholder so as not to hotlink from tailwind's site.)

Given those improvements to the semantic structure of the HTML, here's how you can make the author's name appear on the right, with the quote underneath, with a line break before the company name, and "tiny" in a small font: https://codepen.io/Kerrick/pen/KKXgPYw

Re:Tailwind CSS v3.0 by seanwilson on Thursday December 09, 2021 @09:43PM (#29505869)
> There must be a logical reason for wanting to make the word "tiny" use a small font

> - Similarly, there is missing semantic markup inside the <figcaption> for the person's name, job title and company. Those are semantically separate concepts for each other, but for some reason the example HTML was written without semantically differentiating them.

Presentation/visuals aren't always tied so closely with logic though. "To make it look nice" is a valid reason. As I said, this experiment has failed. All modern website designs use divs + classes everywhere for styling. I agree extra semantic tags would be useful but at some stage you're going to be forcing yourself to come up with semantic reasons to add a tag when there isn't one.

> I've also added the recommended attributes to the image tag, because it was missing.

Related: alt="" is best practice for when an image tag is for presentation purposes only because images don't have to be there for semantic reasons.

Re:Tailwind CSS v3.0 by z3t4 on Friday December 10, 2021 @06:34PM (#29516806)
You don't use CSS to move stuff around. If you for example want to place paragraph-1 below paragraph-2 you simply move it in the HTML. And if you want to add a line break you add <br> in the HTML.

If you want to make a word tiny, you can use the <small> HTML element.

Here is the CSS for my example

  body {
   font-family: sans-serif;
   background: #e4e5f8
  }

  figure {
   text-align: center;
   background: #fff;
   border-radius: 1rem;
   padding: 1.5rem;
   max-width: 40rem;
  }

  figure img {
   border-radius: 50%;
   width: 7rem;
   height: 7rem;
   object-fit: cover;
  }

  figure blockquote {
   font-size: 1.125rem;
   margin: 1rem;
  }

  figure b {
   color: #0ea5e9;
   display: block;
  }

The trick is to keep things simple. Then when you have mastered the rules, you can break the rules. eg. when you can style semantic HTML however you want without adding div's and CSS classes, that's when you can start adding a little div and class here and there just to keep things even more simple.

Simple code is most of the time faster to load, and easier to maintain.

Re:Tailwind CSS v3.0 by BurningPenguin on Friday December 10, 2021 @05:43AM (#29508445)
I tried it just for the lolz and without changing a single bit of HTML. It's absolutely disgusting and nobody in their right mind should do this EVER! Only tested in Chrome, it might fail in other browsers. And on mobile it will very likely break.

https://codepen.io/BlindPenguin/pen/GRMjjvq

I'm off scrubbing my hands with a wire brush and abrasive cleaner.

Re:Tailwind CSS v3.0 by Yzupnick on Thursday December 09, 2021 @06:00PM (#29504265)
I often have trouble writing CSS. Here is how I approached this challenge. https://jsfiddle.net/mwabc719/

Anyone have good advice on a better way?

Re:Tailwind CSS v3.0 by mgkimsal on Thursday December 09, 2021 @06:44PM (#29504720)
You modified the HTML. And... I didn't see the output described in the parent in your fiddle. ?
Re:Tailwind CSS v3.0 by chrisseaton on Thursday December 09, 2021 @07:36PM (#29505066)
> without modifying the HTML

> Here is how I approached this challenge

...but you modified the HTML?

Re:Tailwind CSS v3.0 by dragonwriter on Friday December 10, 2021 @06:02AM (#29508549)
> ...but you modified the HTML?

The original challenge includes questions that apply only if the resolution involves HTML modifications, which (contrary to the earlier text viewed in isolation) indicates that such modifications are not invalid in response to the challenge.

Re:Tailwind CSS v3.0 by Yzupnick on Friday December 10, 2021 @02:10PM (#29514110)
Yah, maybe I should have been explicit, but I think my HTML change as semantically important. (My interpretation of the last line of the challenge.)
Re:Tailwind CSS v3.0 by freebreakfast on Thursday December 09, 2021 @05:12PM (#29503687)
> CSS isn't powerful enough to style HTML however you want without having to add a soup of extra divs and classes that are only there for styling.

Can you provide an example? I've never found this to be the case, particularly with modern CSS. Happy to be wrong though.

Re:Tailwind CSS v3.0 by seanwilson on Thursday December 09, 2021 @05:54PM (#29504184)
Take a look at the https://tailwindcss.com/ page and search for "div". Can you replace them all with more semantic tags? If not, can you remove them and still style it the same way?

You need divs all the time for layout (e.g. to group parents/children in the right way for flexbox), to target content for styling (e.g. putting a div around the name of the author to make it blue when you otherwise wouldn't tag it) and to get around CSS quirks (search for "wrapper div" for examples).

Re:Tailwind CSS v3.0 by freebreakfast on Thursday December 09, 2021 @07:49PM (#29505151)
The discussion is not about the semantic expressiveness of HTML. There are certainly limitations, but these are limitations of HTML. The discussion is about whether or not "tag soup" (excessive HTML elements) is necessary for styling with modern CSS. I cannot think of an example of where it is.

> Can you replace them all with more semantic tags? If not, can you remove them and still style it the same way?

I looked at on the first four examples, but my responses are yes and yes.

Take the figure example. The first div, which groups blockquote and figcaption, is extraneous and unnecessary for the end styling result. The second div is not extraneous because it exists for a purpose. The purpose of the second div is to place emphasis on the name or make it stand out. Thus, it should be changed to em. The third div is extraneous. With the HTML in place, grid it up.

You have the container (figure) with two columns and two rows. The image sits in the first column spanning both rows. The blockquote sits in the second column on the first row. The figcaption sits in the bottom right-hand corner. Then tweak to get your img and other parts as desired (e.g., width, spacing, font-size, etc.).

> You need divs all the time for layout (e.g. to group parents/children in the right way for flexbox) ... to get around CSS quirks (search for "wrapper div" for examples).

Sometimes flexbox is the wrong tool. Sometimes floats are better. Sometimes grid is better. If you find yourself reaching for extra HTML elements first, you should stop and re-evaluate whether your approach to achieving that layout is appropriate.

On quirks, my experience is that "quirks" are rarely actual quirks. They are usually a limited understanding of HTML and CSS.

Re:Tailwind CSS v3.0 by seanwilson on Friday December 10, 2021 @03:17PM (#29514959)
Can you link to any complex designs you've worked on that only use semantic HTML elements and minimal divs/spans? Are you saying that any modern website that uses wrapper divs is from lack of expertise?
Re:Tailwind CSS v3.0 by johnchristopher on Saturday December 11, 2021 @06:06AM (#29520031)
> Are you saying that any modern website that uses wrapper divs is from lack of expertise?

That's a loaded question. CSS frameworks (or tables, or div based designs) are also used because they save time when iterating, not because of a lack of expertise.

Re:Tailwind CSS v3.0 by freebreakfast on Thursday December 09, 2021 @08:20PM (#29505353)
This is a quick and dirty example.

https://jsfiddle.net/gx4hk358/

Re:Tailwind CSS v3.0 by andkon on Thursday December 09, 2021 @05:21PM (#29503777)
You've never put a number of elements together in a div, and added a class and styles to that div rather than each individual element? You should try it out.
Re:Tailwind CSS v3.0 by iovrthoughtthis on Friday December 10, 2021 @06:41PM (#29516859)
nice, now your aesthetic is coupled to your information hierarchy

style is orthogonal to semantics

Re:Tailwind CSS v3.0 by freebreakfast on Thursday December 09, 2021 @07:50PM (#29505160)
I do so for semantics. I don't do it for style.
Re:Tailwind CSS v3.0 by danielvaughn on Thursday December 09, 2021 @07:06PM (#29504873)
Just open up the inspector on any major website like Facebook, Twitter, Github, etc. How complex is the UI you typically work with? Once you get to a certain level of complexity, it's literally not possible to not end up with the div soup.
Re:Tailwind CSS v3.0 by freebreakfast on Thursday December 09, 2021 @10:30PM (#29506097)
It's definitely possible, but it's not done.

And it's hard to take Facebook serious as an example. They're known to engage in HTML obfuscation on purpose.

https://dev.to/ganderzz/how-facebook-avoids-ad-blockers-4mdc

Re:Tailwind CSS v3.0 by tomcooks on Friday December 10, 2021 @01:34AM (#29507037)
Not eparating concerns also fails VERY hard, but that bites you in the arse when you least expect or want it (unlike writing good CSS which takes only patience and studying).

There's a reason why inline styles and important! were to be avoided

Re:Tailwind CSS v3.0 by iovrthoughtthis on Friday December 10, 2021 @06:44PM (#29516878)
how are they separated though? if your css rules apply based on hierarchy they are incredibly tightly coupled to your html.

separate files != separate concerns

Re:Tailwind CSS v3.0 by rendall on Friday December 10, 2021 @09:42AM (#29510392)
> "CSS isn't powerful enough to style HTML however you want without having to add a soup of extra divs..."

This is untrue by any measure.

This might have been true in the days before flex or grid, but with those additions, there is no need for extraneous styling divs.

> "...and classes that are only there for styling."

That part is confusing. Classes? As in CSS classes? CSS has no other purpose than styling.

Re:Tailwind CSS v3.0 by meerita on Friday December 10, 2021 @03:30AM (#29507715)
Exactly. Also you rely on the development criteria and developers switch jobs and they have different mindsets for architecture. The CSS ends with a soap of architectures and technical debt.
Re:Tailwind CSS v3.0 by jolux on Thursday December 09, 2021 @03:54PM (#29502795)
I believe there are accessibility problems with using divs and spans where a more semantic element would suffice.
Re:Tailwind CSS v3.0 by seanwilson on Thursday December 09, 2021 @03:58PM (#29502851)
Yes, you should always be using the elements/tags with the most semantic meaning you can. When you need to add divs, spans and classes for styling reasons though, they're going to be ignored by screen readers so there's no problem here.
Re:Tailwind CSS v3.0 by jolux on Friday December 10, 2021 @01:26AM (#29506997)
Yeah, I guess my concern is that a lot of developers don’t really seem to understand the difference between semantics and style.