Downsides
- Performance
- Don't inherit CSS from parent document
- Makes JavaScript really annoying
How to build Responsive Components?
Element Queries
iframes
Fake Element Queries with JS!
Fake Element Queries with JS
- Watch element
- Detect when it changes size
- Update a class
class="my-component gt-600px"
(Note for anyone browsing these slides: refresh this page if you don't see a flashing gt-600px
class. Something's broken & I haven't had a chance to fix it yet.)
```
.my-component {
color: green
}
/* .my-component:min-width( 600px ) */
.my-component.gt-600px {
color: yellow
}
```
How to build Responsive Components?
Element Queries
iframes
Fake Element Queries with JS!
Ben's Kinda-Boring Recommended Solution™
Use BEM classes
We don't really render our components in infinite contexts...
...most of the time they'll only have 2 or 3 possible parent containers
...and you probably already know the breakpoints where you want the CSS to change
.my-component,
.my-component--does-respond {
color: green
}
@media ( min-width: 1024px ) {
.my-component--does-respond {
color: yellow
}
}
It's cheating, but it does the job for now.
Responsive components:
Components that work everywhere where you need them to.
But what does the future hold?
Web Components
- Isolated, sandboxed chunks of HTML, CSS & JavaScript
- Only in Chrome so far
- Polymer polyfill
Element Queries!
<viewport>
solves circularity
## In summary...
- Design & build libraries of responsive components!
- Use [BEM](http://csswizardry.com/2013/01/mindbemding-getting-your-head-round-bem-syntax/) class names
- We might get Element Queries one day!
# Thanks!
I'm [@bensmithett](https://twitter.com/bensmithett) on the internet