Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's 61 bytes because you're using two spaces instead of tabs! :^)

You can shave off 2 more bytes by using em instead of rem. In your use case they are functionally the same. Rem is em relative to the root element. Your <main> pretty much is the root element.



When fully minified, it's actually 47 bytes: main{max-width:38rem;padding:2rem;margin:auto}

But I think the original is still well into the land of diminishing returns.


Agreed, but OP isn't serving minified content.

I brought up rem vs em because the difference is subtle and if you're byte shaving it's "free" bytes.


The author is not byte shaving. He states that he is striving for "simplicity," which isn't the same thing.


46 bytes if you take out the new line :)


45 if you remove the trailing }.


I definitely considered this! But rem feels more predictable and straightforward. I have seen debates on em vs. rem, and there is certainly value with em in websites that have lots of nested and/or discrete responsive components, but for a very simple site, I quite like rem.


Ue rem when your reference is the base page. Use m when the refrerence. is surrounding text.

As examples, I size page elements in rem, but text elements (usally), in em.

My main, content, article, header, footer, and aside should all generally reference page, and are in rem.

Main body text width, headings (h1 ... h6), super- and sub-scripts, code and pre blocks (often jarringly sized by default) reference the containing unit and should be in em units. Also, generally, figure and table captions, table text, etc.

I prefer to give figure or sub-element (tables, callouts, note boxes, etc.) margins and paddings in em as well.


In my opinion em would be more predictable. With the current configuration, users of this package would only be able to adjust the font size by setting font-size on the html element, but not on the body element or any container elements of the main element, or even the main element itself. That is pretty confusing to me, I think it is a pretty typical expectation that making the font size of a container bigger or smaller should always make everything inside proportionately bigger or smaller.


Are you sure you don't have the meanings reversed? REM is the one that ignores nesting. EM doesn't, so on a simple site it's easier to use correctly.


I'm sure. For that reason (ignoring nesting), I think rem is easier to use correctly. I think what you're getting at is that simple sites have little nesting, therefore em, but I'm thinking about in terms of em being great for say, css framework developers.


Depends on context and reference: https://news.ycombinator.com/item?id=19608806


Remove all spacing to save even more.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: