Front-end development should be fun. Here is a random list of 12 things that will help you battle front-end frustration.
Front-End:Fun, Not Frustration
View Slide
@roy
better box model
* {box-sizing: content-box;}!.element {width: 800px;padding: 100px;border: 10px;}
!.elementmarginborderpaddingwidth: 1020pxwidth: 800px
* {box-sizing: border-box;}!.element {width: 800px;padding: 100px;border: 10px;}
.elementmarginborderpaddingwidth: 800px
great for percentagebased layouts
margins
.element {margin: 100px;}
.element100px.element
.element 200px .element
that’s just the way it is
positioning
.element {position: static;}
.element {position: relative;}
.element {position: relative;left: 100px;}
.element {position: fixed;}
positioning is hard
inlineblock elements
lilililiul
li {display: inline-block;margin: 0;}
li liulli li
ul {font-size: 0;}!li {display: inline-block;margin: 0;font-size: 12px;}
liulli li li
no more floats to clear
verticalalignment
content goes here
table {width: 100%;height: 100%;}!td {vertical-align: middle;text-align: center;}
tables > css
.element {display: table;width: 100%;}!.content {display: table-cell;vertical-align: middle;text-align: center;}
semantic markup,behaving like tables
pretty buttons
vsSubmit
important button
just use
pseudoelements
.element::before {content: “string”;}!.element::after {content: “\2764”;}
.element:before {content: “string”;}!.element:after {content: “\2764”;}
a[href^=“https”]:after {content: “ (uses SSL)”;}
a[href^=“https”]:after {content: “”;display: inline-block;width: 12px;height: 12px;background: image-url(“lock.png”);}
*,*:before,*:after {box-sizing: border-box;}
less markup,more responsive
css selectors
vscycle():nth-child(odd):nth-child(even)
tr:nth-child(even) td {background: gray;}
a[href$=“.pdf”]:after {content: “ (PDF)”;}
:target {background: red;}
Some content!http://example.com/#foo
a spec worth reading
css animations
a {color: red;transition: color .5s;}!a:hover {color: blue;}
.sidebar {width: 0;transition: width 1s;}!.sidebar.active {width: 200px;}!$(‘.sidebar’).toggleClass(‘active’);
.element {transform: translateZ(0);}
hardware acceleration
fluidity
.element {min-width: 320px;max-width: 1280px;margin: 0 auto;}
low hanging fruit
power of sass
%underline-on-hover {text-decoration: none;!&:hover {text-decoration: underline;}}!.some-link {@extend %underline-on-hover;}
$sass-list: (“locked”: “lock.png”,“error”: “exclamation-mark.png”);!@each $key, $value in $sass-list {.#{$key} {background: image-url($value);}}
it’s like programming
svg
retina friendly,compresses well
Questions?@roy[email protected]slides: roy.io/railsconf
Image credits:!https://www.flickr.com/photos/kunfy/6801036541!https://www.flickr.com/photos/cmichel67/9428306062