Frontend Guidelines (github.com)
over 8 years ago from Benjamin De Cock, UI Designer at Stripe
over 8 years ago from Benjamin De Cock, UI Designer at Stripe
The units section really got me. Responsive principals point to the contrary. Any reason to stick with px over (r)em, particularly with typography?
While relative units are theoretically superior, they're in my experience confusing and harder to work with.
So its not a best practice, its something you do because you find them confusing?
I came back to px
recently after using em
/rem
for years. Relative units used to be very important (notably on IE where fonts wouldn't be resizable otherwise) but that's not the case anymore. They're now harder to use for no good reason, basically.
They're still useful. Try zooming in an out of a page without relative units. People still use zoom on desktop.
Feel free to adopt relative units then :)
What browsers are you zooming on? Chrome, Firefox, Safari and modern.IE zoom everything proportionally, relative units or not.
Relative units (em) are superior to absolute units (px) when you change the default font-size of the browser. If you use relative units for your media queries then the layout will behave the same way as zooming in on the page (control/command +). If you use pixels nothing will change.
Example: visit https://css-tricks.com and change your default font-size to 32px for dramatic effect. Nothing happens. Now do the same at http://www.americanpressinstitute.com
Yeah, very much a preference. Rem is the correct unit to use IMO, but I've found it hard to use with larger group efforts.
It looks like we've come to the conclusion that px
is a preference for @bdc based on his opinion, so I'd like to share how and why I use rem
, others may find this useful :)
My main reason for using rem
is in order to easily keep margins, padding, and other whitespace-affecting things consistent with font size and well-proportioned. I make three basic assumptions:
That means the standard margin is the width of a single "M" character at the most common font size, which can be set in the html
selector in CSS, and if I want to use that standard margin I need look no further than 1rem
. I can easily figure out a small margin using 0.5rem
and a large one using 2rem
. It's a good starting point, at least.
Then if you decide that you want to change the base font size and thus the margins, you need only change it in one place, the html
selector.
This works really well for me. Any disagreements/opinions?
Getting a good amount of heat here - you must be doing something right :P I was curious about you ommitance of the <head>
and <body>
tags, in the Brevity section. It's my understanding that this will cripple older browsers, no?
*Disclaimer - I have to make sites that work on IE8 :x
I am also curious about this
Yeh, I think even HTML5 Shiv requires an explicit body tag to work.
Someone's been drinking functional programming kool-aid :-)
haha indeed! :)
I tend to agree with most of these.
Why use hex over HSV or HSL? I've grown fond of this over the past nine months.
Being a very old hand, I find keeping the HEAD and BODY tags makes it easier to mentally place things.
Thanks for compiling and presenting.
I like HSL per se too, but it is unfortunately pretty much useless in practice as most design tools use HSB instead.
Ahh. I found colorizer.org a while back, but truth be told, I still fire up PhotoShop for color combo info. This is for generating images for print documentation.
I use LESS and its lighten/darken functions use HSL. It didn't realize until comparing output colors with mockups from Photoshop that HSL and HSB aren't the same. Sometimes the difference is subtle, other times it's very noticeable.
I now use tint/shade functions instead of lighten/darken. They get closer to the intended color, but the resulting value still isn't identical to one Photoshop generates. However I like that with tint/shade produces more gradations of color before turning pure white or black.
Looks good, but what's your reasoning behind dropping the <head>
and <body>
tags? I've never seen that done before.
They're optional in HTML5. The html
element is optional too but I recommend to keep it in order to define the document's language at root level.
Ah okay! I had no idea about that.
I noticed doing this cripples older browsers pretty bad, no?
I hadn't seen it before either. I like it!
Lost me at this selector listed under "Good": li + li {...}
It's too specific, IMHO, and inefficent.
(edited for clarity)
I'm… not sure to get your point. ಠ_ಠ
Oh, hmm. There is a section in your README.md called "Specificity". Anyway, you're using both tag and descendent selectors there.
"The descendant selector is the most expensive selector in CSS. It is dreadfully expensive — especially if the selector is in the Tag or Universal Category."
li + li
is not a descendant selector.You are not allowed to care about the performance of * unless you concatenate all your javascript, have it at the bottom, minify your css and js, gzip all your assets, and losslessly compress all your images.
Woops, you're right on the descendent/sibling selector mixup. :coffee: Using two tag selectors like that still makes me cringe.
I have a lot of respect for Paul Irish, but I think that quote is absolutely absurd.
Nope, it's not absurd. It's, in fact, 100% right.
To me that sounds like "I'm not going to combat climate change because the rest of the world isn't."
Do your part.
Edit:
Let me revise the above statement... Stylesheets that are expensive to execute and serving big files are two totally different issues and you should care about both of them. It's like, "I don't care about climate change because there's a polio crisis in western Africa."
Stylesheets aren't expensive to execute at all. Do some research. End of topic, please.
So it would be better to pollute your stylesheets with .first or .last classes because it would save you a few of microseconds or whatnot of parsing?
I'd argue using a adjacent sibling selector is far more maintainable than having to remember to always add superfluous selectors in your markup.
Well, I would use an nth selector or something for targeting the first or last instance of an element if it made sense absolutely.
Sure, the performance hit might be very slight in isolation. However I've found that when maintaining a large project over the course of many years, you can easily find yourself dealing with a "death-by-a-thousand-papercuts" kind of situation if you rely too heavily on the more convenient selectors.
My opinions favor my preference, but I'm just trying to be pragmatic. I don't see an extra handful of classes as "pollution" or less maintainable at all. I see it as a greater separation of concerns, in that I would rather my styles not be so coupled to a particular HTML structure as is the case with adjacent sibling selectors and the like.
For context: More times than I can count, I've been working on a project with my team where I style some stuff using sibling selectors or something, only to have the layout break when Backbone wraps each element (view) in a div, or Ember spits out a bunch of <script>
tags.
These are easy enough problems to solve and many of these particular annoyances seem to be going away as the frameworks (and techniques) mature, but dealing with that has greatly influened my preferences.
Curious why you advocate not modifying the global box model?
Ah, gotcha.
For what it's worth, listing all the elements that box model affects is more performant than applying it globally.
Lots of nice stuff here in here, which generally means, lots of stuff that I agree with.
Omitting the option head/body is still a big foreign to me, but I get it. I probably just like the structure.
I'd be interested to hear about why you should avoid altering the default box model though. Not advocating use of the universal selector and gutting the whole thing, but I don't find much issue with changing it as needed.
Mostly for consistency. I'd actually be fine with a global * { box-sizing: border-box; }
, but changing the behavior for just some elements is misleading imho. The example I provided in the guidelines shows a particularly bad use case for box-sizing: border-box
: there's no need for a block element to get a width: 100%
.
True, in that example it's superfluous. I got stuck at the headline apparently.
Designer News
Where the design community meets.
Designer News is a large, global community of people working or interested in design and technology.
Have feedback?
Login to Comment
You'll need to log in before you can leave a comment.
LoginRegister Today
New accounts can leave comments immediately, and gain full permissions after one week.
Register now