215 points · by czottmann · 11y ago · 94 comments
<ul class="collection">
<li class="collection-item">Alvin</li>
<li class="collection-item">Alvin</li>
<li class="collection-item">Alvin</li>
<li class="collection-item">Alvin</li>
</ul>
Rather than assigning a "collection-item" class to each "li", would you not simply style the "li" in the context of "collection"?Bootstrap does a similar thing. Drives me nuts...
There are two problems with your suggested approach -- specificity and coupling. The rules of CSS are such that .collection > li is a more specific selector than .collection-item. So if you want a particular item in the list to be red, you can't just give it a class name .warning-item and style against that -- you have to match or exceed the existing specificity. In the simple case, this isn't too bad, but it's surprisingly easy to end up representing deeply nested structures in your CSS which are very difficult to override.
The coupling problem is really just a way of saying that it might not be a good idea to describe the specifics of your HTML implementation in CSS. Class names are like an interface. One refactoring I've actually done a lot is switching out lists like the above for a combination of nav and anchor elements. It's great to be able to do that without needing to rewrite all the corresponding CSS, too.
These are tools designed to help you manage complexity and increase flexibility, not dogma. If you don't find your HTML needing to change much, or you don't need to make styles overrideable, then YAGNI. Hopefully it makes sense why framework authors, whose work is explicitly designed to be overridden, would choose this approach.
I'm just provided the link here in case anyone else was wondering the same thing.
I tend to agree with you, but I was heavily chastised by lead the front end dev at my last gig for ever directly applying design styles to tag entities as doing it as above is considered best practice at the moment (until the cycle comes around again to another best practice).
You want one collection li's to not have the style? Use an alternative class on the ul: "collection collection-alt".
You want nested li's to not inherit the styles? Use ".collection > li" in your CSS.
In any case, assigning a class on each li goes exactly against CSS best practices, because it prevents taking advantage of the inheritance of property values or of advanced selectors.
I think the whole community went to separating the HTML tag names from the styles and work only with class names [1].
If you start styling your tags directly it imminently increase the code debt if you scale. Let's say you just want to add another element inside the tag. I can give you example :
<ul class='collection'><li></li></ul>
.collection > li { color: red; }
and later on you add a anchor as a child you would need to force the specificy to this element <ul class='collection'><li><a class='collection-link'></a></li></ul>
.collection-link { color: blue; } // this will not work
.collection > li .collection-link { color: blue; } // increased complexity
I would almost always advice against styling tag names, except when you are doing css reset.I guess it's come about from trying to be more semantic within the documents.
Declaring Headings with classes is a good example as well.
h1,
.h1{
font-size:20px;
}
h2,
.h2{
font-size:18px;
}
etc... This allows you to apply <h1> styles to <h3> or even <p>'s while still keeping the content semantically correct and designers happy.Another few other common ones are
strong,
.strong{
font-weight:600;
}
small,
.small{
text-size:10px;
}
The same can go with .collection, somebody may want to use the styles on something thats not a list for example <div>'s.It also does not really go against inheritance, themes like .collection-alt can still work.
Sometimes its an overkill and I don't always do it, but in some cases (heavily responsive sites) it has worked really well. Its also easier to work in a team with one approach, rather then just doing it for headings etc why not take the principle/standard across all styles.
...don't exist. There are many competing schools of thought. In particular, BEM is a school of thought with widespread support which disagrees with your comment.
https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Writi...
Using nesting and tags is less performant than classes. So using more classes is better than less.
<ul class="collection"> <li class="collection-item"> <ul> <li>Bulleted label</li> <li>Bulleted label 2</li> </ul> </li> </ul>
This case must be considered when setting coding standards for a framework.
I'd say, keep it DRY [1].
https://github.com/suitcss/suit/blob/master/doc/naming-conve...
Using element names instead of class names can be problematic. In some frameworks you may need to use a different element or an element that wraps another element to achieve certain functionality.
Some use generic names like "button large" as class names, but, again in my personal experience, it often causes problems. You might have other elements that need to be "large" and may need to be inside a button - but which "large" do you mean.
So to keep things predictable, I've adopted the following practices:
- Always namespace components.
- Always ensure that selectors work even if the child has a wrapper around it.
- Whenever possible use classnames instead of element names.
And to ensure I don't get tendonitis (not sure if everyone agrees with this):
- If possible provide a shorthand for at least the most used components (i.e. "col"/"col-i" for "collection"/"collection-item"
I am often heard saying (in classes, public presentations, etc.), "I don't like the phrase 'best practice'. It implies that someone knows your requirements better than you. So I don't use it. What's 'best' for me might suck for you. So I say: the best practice is, in many cases, simply to have a practice that you and your team adhere to. One which meets your requirements, now and foreseen."
Class-itis, div-itis, selector-nesting-itis... They all have a place in the Real World.
I'm not a Google fanboy, but I believe Material is the best visual language for UI. Okay, there are different contexts, but it's best thought-through, and most modern.
For instance, the use of animation is finally mature and at the same rich and amplifying user experience (rather than being an eye-candy).
And I think it's very compatible with web apps.
A Material-ish popular chess site: http://en.lichess.org/ (I'm in no way associated, but a happy user)
and that's before we get into the lack of shadow
So we are not talking about the same thing, because Material uses shadows extensively - certainly more so than older versions on Android. See https://developer.android.com/training/material/shadows-clip... and http://www.google.com/design/spec/what-is-material/objects-i... for more details- The required HTML classes seemed kinda bloated and not semantic, but I intended to fix that with Sass (well, officially they're on Less)
- The input elements have weird animation on page load
- When I just dropped in some basic elements, like an input field (with its wrappers) nothing was really working. Things were not properly aligned and I had to add all this container/row/column stuff, even though I just came for the widgets
And last but not least what made me finally ditch it:
- To display form validation errors, I have to supply a data-error attribute which will then get rendered via css as a pseudo ::after to the label. That is just weird. I then checked how it works without JavaScript and saw labels overlapping placeholders.
It looks beautiful and I like how comprehensive it is. Really hope they'll improve on some of these technical flaws.
Let me know what you think!
The menu animation is really slow on Firefox 37 on Mac OS X. The way pages load and then more animations happen seems jarring. I've not used any material based apps, so maybe I'm just not used to how things work.
Specifically, the range input uses a bubble on mouseover, which is not touch-screen friendly. I've also had minor issues with the select widget not closing after a selection is made. Additionally, the styles for labels is inconsistent amongst different input types.
For everything else, this library is wonderful. The forms area could use some polish.
But there were two annoyances: Select elements (without .browser-default class) are display:none and only shown, when initiated via javascript and similarly checkboxes are put off screen and thus invisible if there's no corresponding label (in my case the ones to select rows in a table).
Of course they were easily fixed. But it seems odd to me, to make unexpected things like that the default behavior and – in the case of the selects – risk making your site/app unusable if something goes wrong in your js just to avoid a flash of unstyled content.
Great work.
Edit: Why is this getting downvoted? This is a page made to present a framework based on material design. Flickering instead of smoothly presenting content is the anti-thesis of material design. If your demo page features a big annoying issue, this is giving a very bad impression to your users.
Desktop:
I tried this by progressively shrinking my (desktop) browser window width to around 200px, and the main content seemed to get stuffed under the left menu with no responsive re-layout. [IE 11 on Windows 8.1].
Mobile:
I tried on my mobile (Android 4.4.2 480*800, Firefox - worked OK on default browser) the design was definitely for mobile (no problem like the above) apart from a ~20px white margin for the content on the right.
http://sgasser.github.io/ember-cli-materialize https://github.com/sgasser/ember-cli-materialize
Bootstrap is quite web focused still so I guess it will come when support for IE9 is not expected.
Though if you are doing an mobile/tablet only solution I would probably use flexbox only now. As long as you keep to the 2012 spec, you should be ok.
http://caniuse.com/#feat=flexbox
Bring on the death of IE9!!
Compare https://www.straphq.com/ with Jennifer Estep (author) 2009 [1]
Compare: http://danielangel.media/ with Girbaud (designer jeans, now defunct) 2005 [2] 2012[3]
[1] https://web.archive.org/web/20070408092333/http://www.jennif...
[2] https://web.archive.org/web/20051130094152/http://www.girbau... [3] https://web.archive.org/web/20120207224137/http://www.girbau...
It's effectively CC BY-SA-NC which is rather bold when you consider that it's adopting a design framework from Google for a css framework from Twitter.
[0] https://github.com/FezVrasta/bootstrap-material-design/blob/...
[1] https://github.com/FezVrasta/bootstrap-material-design/searc...
> There will be a commercial license as well. [0]
Well, if he goes that far, perhaps Google or Twitter lawyers will finally put an end to this.
[0] https://github.com/FezVrasta/bootstrap-material-design/issue...
Does this really make a difference? Even if it did, wouldn't it lead to seeing a jump in the content after the CSS loads?
This lets my templates contain initialization functions inside of $(document).ready(function() {...}); calls without running into a "$ not defined" error.
The alternative would be to somehow bubble up from my templates a list of initialization functions to call, or to have every page load run through a bunch of tests to find things that need to be initialized. I think the tradeoff of loading jQuery early is worth it, especially since I usually load it from Google's CDN so it's probably cached.
As a general best practice don't load -any- javascript in the head. Only at the end of the body tag right before `</body>`