Skip to content

Instantly share code, notes, and snippets.

@lsmag
Created May 16, 2014 12:19
Show Gist options
  • Save lsmag/2d2aa579305f5f63b58b to your computer and use it in GitHub Desktop.
Save lsmag/2d2aa579305f5f63b58b to your computer and use it in GitHub Desktop.
BEM
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Teste BEM (Block-Element-Modifier)</title>
<link href='http://fonts.googleapis.com/css?family=Lato:300,400,700|Roboto:400,300,700' rel='stylesheet' type='text/css'>
<link href="./normalize.css" rel="stylesheet">
<!--
<link href="./styles.css" rel="stylesheet">
-->
<link href="./new-styles.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="container__aside">
<div class="account-header">
<a class="account-header__link" href="#">Settings</a>
<a class="account-header__link" href="#">Sign Out</a>
<a class="account-header__link account-header__link--counter" href="#">4</a>
<img class="account-header__avatar" src="http://robohash.org/lucas.sampaio">
</div>
<div class="search-bar">
<input class="search-bar__input" type="text" placeholder="Search">
<button class="search-bar__button">Go!</button>
</div>
<div class="container__aside__update media">
<img class="media__avatar media__avatar--big" src="http://robohash.org/marcus.souza">
<div class="media__body">
<a href="#">Marcus Souza</a>
Nulla beef kevin tempor aute.
</div>
</div>
<div class="container__aside__update media">
<img class="media__avatar media__avatar--big" src="http://robohash.org/vanderson.mota">
<div class="media__body">
<a href="#">Vanderson Mota</a>
Mollit nostrud esse jerky non corned beef ribeye landjaeger culpa veniam ex.
</div>
</div>
<div class="container__aside__update media">
<img class="media__avatar media__avatar--big" src="http://robohash.org/pedro.teixeira">
<div class="media__body">
<a href="#">Pedro Teixeira</a>
Sunt veniam dolore, ham hock non pancetta biltong fugiat rump velit aliquip.
</div>
</div>
</div>
<div class="container__main">
<div class="thread">
<div class="thread__likes">
<img class="thread__likes__avatar" src="http://robohash.org/paula.andrea">
<img class="thread__likes__avatar" src="http://robohash.org/julia.sampaio">
<img class="thread__likes__avatar" src="http://robohash.org/alberto.jose">
<img class="thread__likes__avatar" src="http://robohash.org/denise.bussu">
<img class="thread__likes__avatar" src="http://robohash.org/deraldo.junior">
<a class="thread__likes__more-counter" href="#">+17</a>
<a class="thread__likes__like-button" href="#">Heart it</a>
</div>
<h1 class="thread__header">
A Kid Stands Up To Literally Everyone In His Class
</h1>
<div class="thread__posted-by">
<div class="media">
<img class="media__avatar media__avatar--circle" src="http://robohash.org/fulano.da.silva">
<p class="media__body">
Fulano Da Silva, ontem às 8h52
</p>
</div>
</div>
<p class="thread__content">
I’ve had a lot of heroic moments where I face a bully and
give them a piece of my mind. Unfortunately, they’re all
in my head. Watch this kid do a very brave, very rare
thing: stand up for himself.
</p>
<img class="thread__image" src="http://homeschoolhappy.com/images/2012/07/iStock_000017812712Medium.jpg">
<p class="thread__content">
Jake is now a junior in high school, and unsurprisingly, he’s
doing great. Here’s an update directly from him:
</p>
<p class="thread__content">
"Bullying has had a big impact on my life, but since the movie
I’ve made a lot of friends. Recently, I have joined my high
school football team! At first I thought they would all be
complete jerks, but actually they are pretty cool guys and
have helped me through a lot of situations — they stand up
for me!
</p>
<p class="thread__content">
"For other kids with autism, if you're getting bullied, try and
tell them to stop and not give a reaction — if that doesn’t
work, go to an adult. It might seem hard cause we can’t handle
stress as well as other kids, but you will get through it and
you’ll be awesome — actually you already are!
</p>
<p class="thread__content">
"Bullying does not make you cool — you might think you are on
the top of the food chain — but you’re not going to be
there forever."
</p>
<div class="thread__comments">
<div class="media">
<img class="media__avatar" src="http://robohash.org/pedro.teixeira">
<p class="media__body">
<a href="#">Pedro Teixeira</a>
Bacon ipsum dolor sit amet turkey brisket quis rump ea
magna. Proident filet mignon tempor mollit. Culpa anim
meatball, meatloaf ground round in spare ribs eiusmod
ea ribeye elit.
</p>
</div>
<div class="media">
<img class="media__avatar" src="http://robohash.org/vanderson.mota">
<p class="media__body">
<a href="#">Vanderson Mota</a>
Flank ground round reprehenderit ham hock pig fatback
corned beef pastrami officia pork belly pork chop
est cupidatat tenderloin.
</p>
</div>
<div class="thread__comments__commentbox">
<img class="thread__comments__commentbox__avatar" src="http://robohash.org/lucas.sampaio">
<textarea class="thread__comments__commentbox__input" placeholder="Write your comment..."></textarea>
<button class="thread__comments__commentbox__submit">
Comment
</button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box; }
.container {
font-size: 14px;
font-family: "Roboto", sans-serif;
color: #323231; }
.container__aside {
position: absolute;
top: 0;
left: 0;
width: 300px;
height: 100%;
overflow: auto;
background: #f9f9f9;
border-right: 1px solid #ddd; }
.container__aside__update {
border-bottom: 1px solid #ddd; }
.container__aside__update:hover {
background: #fff;
cursor: pointer; }
.container__main {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 300px;
overflow: auto; }
.account-header {
height: 40px;
background: #00A0B0; }
.account-header__link {
margin: 5px;
line-height: 40px;
font-family: "Lato", sans-serif;
font-size: 0.9em;
color: #323231;
text-decoration: none; }
.account-header__link:hover {
text-decoration: underline; }
.account-header__link--counter {
padding: 2px 5px;
background: #cc333f;
border-radius: 5px;
color: #fff; }
.account-header__avatar {
height: 30px;
margin: 5px;
float: right; }
.search-bar {
height: 40px;
padding: 5px;
font-size: 0.9em;
border-bottom: 1px solid #ddd; }
.search-bar__input {
border: none;
height: 20px;
width: 250px;
margin: 5px 0;
background: #f9f9f9; }
.search-bar__button {
height: 20px;
width: 30px;
padding: 1px 5px;
margin: 5px 0;
border: none;
border-radius: 3px;
float: right;
background: #00a0b0; }
.media {
overflow: hidden;
zoom: 1; }
.media__avatar {
width: 50px;
float: left;
margin: 10px; }
.media__avatar--big {
width: 80px;
margin: 0 10px 0 0; }
.media__avatar--circle {
background: #ddd;
width: 30px;
border-radius: 15px;
margin: 5px; }
.thread {
width: 600px;
margin: 60px auto; }
.thread__likes {
height: 40px;
overflow: hidden;
margin-bottom: 40px; }
.thread__likes__avatar {
background: #ddd;
float: left;
width: 30px;
border-radius: 15px;
margin: 5px; }
.thread__likes__more-counter {
display: inline-block;
float: left;
background: #ddd;
color: #323231;
width: 30px;
line-height: 30px;
border-radius: 15px;
margin: 5px;
font-size: 0.8em;
text-align: center;
text-decoration: none; }
.thread__likes__like-button {
display: inline-block;
float: right;
background: #cc333f;
color: #fafafa;
line-height: 30px;
border-radius: 3px;
line-height: 20px;
padding: 5px;
margin: 5px;
text-decoration: none; }
.thread__header {
font-family: "Lato", sans-serif;
font-weight: 300;
font-size: 2.5em; }
.thread__posted-by {
height: 40px;
overflow: hidden;
margin-bottom: 40px; }
.thread__content {
font-size: 16px;
line-height: 1.4em; }
.thread__image {
width: 100%;
border-radius: 5px;
margin: 20px 0; }
.thread__comments {
margin-top: 60px;
padding: 10px;
border-top: 1px solid #ddd; }
.thread__comments__commentbox__avatar {
width: 50px;
margin: 10px; }
.thread__comments__commentbox__input {
border: 1px solid #ddd;
height: 50px;
width: 506px;
margin: 10px 0; }
.thread__comments__commentbox__submit {
display: inline-block;
border: none;
float: right;
background: #cc333f;
color: #fafafa;
line-height: 30px;
border-radius: 3px;
line-height: 20px;
padding: 5px;
text-decoration: none; }
$header-font-stack: 'Lato', sans-serif;
$font-stack: 'Roboto', sans-serif;
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.container {
font-size: 14px;
font-family: $font-stack;
color: #323231;
&__aside {
position: absolute;
top: 0;
left: 0;
width: 300px;
height: 100%;
overflow: auto;
background: #f9f9f9;
border-right: 1px solid #ddd;
&__update {
border-bottom: 1px solid #ddd;
&:hover {
background: #fff;
cursor: pointer;
}
}
}
&__main {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 300px;
overflow: auto;
}
}
.account-header {
height: 40px;
background: #00A0B0;
&__link {
margin: 5px;
line-height: 40px;
font-family: $header-font-stack;
font-size: 0.9em;
color: #323231;
text-decoration: none;
&:hover {
text-decoration: underline;
}
&--counter {
padding: 2px 5px;
background: #cc333f;
border-radius: 5px;
color: #fff;
}
}
&__avatar {
height: 30px;
margin: 5px;
float: right;
}
}
.search-bar {
height: 40px;
padding: 5px;
font-size: 0.9em;
border-bottom: 1px solid #ddd;
&__input {
border: none;
height: 20px;
width: 250px;
margin: 5px 0;
background: #f9f9f9;
}
&__button {
height: 20px;
width: 30px;
padding: 1px 5px;
margin: 5px 0;
border: none;
border-radius: 3px;
float: right;
background: #00a0b0;
}
}
.media {
overflow: hidden;
zoom: 1;
&__avatar {
width: 50px;
float: left;
margin: 10px;
&--big {
width: 80px;
margin: 0 10px 0 0;
}
&--circle {
background: #ddd;
width: 30px;
border-radius: 15px;
margin: 5px;
}
}
}
.thread {
width: 600px;
margin: 60px auto;
&__likes {
height: 40px;
overflow: hidden;
margin-bottom: 40px;
&__avatar {
background: #ddd;
float: left;
width: 30px;
border-radius: 15px;
margin: 5px;
}
&__more-counter {
display: inline-block;
float: left;
background: #ddd;
color: #323231;
width: 30px;
line-height: 30px;
border-radius: 15px;
margin: 5px;
font-size: 0.8em;
text-align: center;
text-decoration: none;
}
&__like-button {
display: inline-block;
float: right;
background: #cc333f;
color: #fafafa;
line-height: 30px;
border-radius: 3px;
line-height: 20px;
padding: 5px;
margin: 5px;
text-decoration: none;
}
}
&__header {
font-family: $header-font-stack;
font-weight: 300;
font-size: 2.5em;
}
&__posted-by {
height: 40px;
overflow: hidden;
margin-bottom: 40px;
}
&__content {
font-size: 16px;
line-height: 1.4em;
}
&__image {
width: 100%;
border-radius: 5px;
margin: 20px 0;
}
&__comments {
margin-top: 60px;
padding: 10px;
border-top: 1px solid #ddd;
&__commentbox__avatar {
width: 50px;
margin: 10px;
}
&__commentbox__input {
border: 1px solid #ddd;
height: 50px;
width: 506px;
margin: 10px 0;
}
&__commentbox__submit {
display: inline-block;
border: none;
float: right;
background: #cc333f;
color: #fafafa;
line-height: 30px;
border-radius: 3px;
line-height: 20px;
padding: 5px;
text-decoration: none;
}
}
}
/*! normalize.css v3.0.1 | MIT License | git.io/normalize */
/**
* 1. Set default font family to sans-serif.
* 2. Prevent iOS text size adjust after orientation change, without disabling
* user zoom.
*/
html {
font-family: sans-serif; /* 1 */
-ms-text-size-adjust: 100%; /* 2 */
-webkit-text-size-adjust: 100%; /* 2 */
}
/**
* Remove default margin.
*/
body {
margin: 0;
}
/* HTML5 display definitions
========================================================================== */
/**
* Correct `block` display not defined for any HTML5 element in IE 8/9.
* Correct `block` display not defined for `details` or `summary` in IE 10/11 and Firefox.
* Correct `block` display not defined for `main` in IE 11.
*/
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
main,
nav,
section,
summary {
display: block;
}
/**
* 1. Correct `inline-block` display not defined in IE 8/9.
* 2. Normalize vertical alignment of `progress` in Chrome, Firefox, and Opera.
*/
audio,
canvas,
progress,
video {
display: inline-block; /* 1 */
vertical-align: baseline; /* 2 */
}
/**
* Prevent modern browsers from displaying `audio` without controls.
* Remove excess height in iOS 5 devices.
*/
audio:not([controls]) {
display: none;
height: 0;
}
/**
* Address `[hidden]` styling not present in IE 8/9/10.
* Hide the `template` element in IE 8/9/11, Safari, and Firefox < 22.
*/
[hidden],
template {
display: none;
}
/* Links
========================================================================== */
/**
* Remove the gray background color from active links in IE 10.
*/
a {
background: transparent;
}
/**
* Improve readability when focused and also mouse hovered in all browsers.
*/
a:active,
a:hover {
outline: 0;
}
/* Text-level semantics
========================================================================== */
/**
* Address styling not present in IE 8/9/10/11, Safari, and Chrome.
*/
abbr[title] {
border-bottom: 1px dotted;
}
/**
* Address style set to `bolder` in Firefox 4+, Safari, and Chrome.
*/
b,
strong {
font-weight: bold;
}
/**
* Address styling not present in Safari and Chrome.
*/
dfn {
font-style: italic;
}
/**
* Address variable `h1` font-size and margin within `section` and `article`
* contexts in Firefox 4+, Safari, and Chrome.
*/
h1 {
font-size: 2em;
margin: 0.67em 0;
}
/**
* Address styling not present in IE 8/9.
*/
mark {
background: #ff0;
color: #000;
}
/**
* Address inconsistent and variable font size in all browsers.
*/
small {
font-size: 80%;
}
/**
* Prevent `sub` and `sup` affecting `line-height` in all browsers.
*/
sub,
sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline;
}
sup {
top: -0.5em;
}
sub {
bottom: -0.25em;
}
/* Embedded content
========================================================================== */
/**
* Remove border when inside `a` element in IE 8/9/10.
*/
img {
border: 0;
}
/**
* Correct overflow not hidden in IE 9/10/11.
*/
svg:not(:root) {
overflow: hidden;
}
/* Grouping content
========================================================================== */
/**
* Address margin not present in IE 8/9 and Safari.
*/
figure {
margin: 1em 40px;
}
/**
* Address differences between Firefox and other browsers.
*/
hr {
-moz-box-sizing: content-box;
box-sizing: content-box;
height: 0;
}
/**
* Contain overflow in all browsers.
*/
pre {
overflow: auto;
}
/**
* Address odd `em`-unit font size rendering in all browsers.
*/
code,
kbd,
pre,
samp {
font-family: monospace, monospace;
font-size: 1em;
}
/* Forms
========================================================================== */
/**
* Known limitation: by default, Chrome and Safari on OS X allow very limited
* styling of `select`, unless a `border` property is set.
*/
/**
* 1. Correct color not being inherited.
* Known issue: affects color of disabled elements.
* 2. Correct font properties not being inherited.
* 3. Address margins set differently in Firefox 4+, Safari, and Chrome.
*/
button,
input,
optgroup,
select,
textarea {
color: inherit; /* 1 */
font: inherit; /* 2 */
margin: 0; /* 3 */
}
/**
* Address `overflow` set to `hidden` in IE 8/9/10/11.
*/
button {
overflow: visible;
}
/**
* Address inconsistent `text-transform` inheritance for `button` and `select`.
* All other form control elements do not inherit `text-transform` values.
* Correct `button` style inheritance in Firefox, IE 8/9/10/11, and Opera.
* Correct `select` style inheritance in Firefox.
*/
button,
select {
text-transform: none;
}
/**
* 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio`
* and `video` controls.
* 2. Correct inability to style clickable `input` types in iOS.
* 3. Improve usability and consistency of cursor style between image-type
* `input` and others.
*/
button,
html input[type="button"], /* 1 */
input[type="reset"],
input[type="submit"] {
-webkit-appearance: button; /* 2 */
cursor: pointer; /* 3 */
}
/**
* Re-set default cursor for disabled elements.
*/
button[disabled],
html input[disabled] {
cursor: default;
}
/**
* Remove inner padding and border in Firefox 4+.
*/
button::-moz-focus-inner,
input::-moz-focus-inner {
border: 0;
padding: 0;
}
/**
* Address Firefox 4+ setting `line-height` on `input` using `!important` in
* the UA stylesheet.
*/
input {
line-height: normal;
}
/**
* It's recommended that you don't attempt to style these elements.
* Firefox's implementation doesn't respect box-sizing, padding, or width.
*
* 1. Address box sizing set to `content-box` in IE 8/9/10.
* 2. Remove excess padding in IE 8/9/10.
*/
input[type="checkbox"],
input[type="radio"] {
box-sizing: border-box; /* 1 */
padding: 0; /* 2 */
}
/**
* Fix the cursor style for Chrome's increment/decrement buttons. For certain
* `font-size` values of the `input`, it causes the cursor style of the
* decrement button to change from `default` to `text`.
*/
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
height: auto;
}
/**
* 1. Address `appearance` set to `searchfield` in Safari and Chrome.
* 2. Address `box-sizing` set to `border-box` in Safari and Chrome
* (include `-moz` to future-proof).
*/
input[type="search"] {
-webkit-appearance: textfield; /* 1 */
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box; /* 2 */
box-sizing: content-box;
}
/**
* Remove inner padding and search cancel button in Safari and Chrome on OS X.
* Safari (but not Chrome) clips the cancel button when the search input has
* padding (and `textfield` appearance).
*/
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration {
-webkit-appearance: none;
}
/**
* Define consistent border, margin, and padding.
*/
fieldset {
border: 1px solid #c0c0c0;
margin: 0 2px;
padding: 0.35em 0.625em 0.75em;
}
/**
* 1. Correct `color` not being inherited in IE 8/9/10/11.
* 2. Remove padding so people aren't caught out if they zero out fieldsets.
*/
legend {
border: 0; /* 1 */
padding: 0; /* 2 */
}
/**
* Remove default vertical scrollbar in IE 8/9/10/11.
*/
textarea {
overflow: auto;
}
/**
* Don't inherit the `font-weight` (applied by a rule above).
* NOTE: the default cannot safely be changed in Chrome and Safari on OS X.
*/
optgroup {
font-weight: bold;
}
/* Tables
========================================================================== */
/**
* Remove most spacing between table cells.
*/
table {
border-collapse: collapse;
border-spacing: 0;
}
td,
th {
padding: 0;
}
Block -> Element -> Modifier
- Blocks devem ser INDEPENDENTES. Se dependem de um contexto
, devem ser um Element.
- seletores de elemento não devem ser usados (idealmente falando)
- cascading deve ser evitado (normalmente)
- ".caps", etc
- .thread__block OU .thread__likes+.thread__content__poster
- thread__comments__commentbox__avatar (nesting mto avançado =S)
http://bem.info/method/
http://www.smashingmagazine.com/2012/04/16/a-new-front-end-methodology-bem/
http://csswizardry.com/2013/01/mindbemding-getting-your-head-round-bem-syntax/
http://www.stubbornella.org/content/2010/06/25/the-media-object-saves-hundreds-of-lines-of-code/
http://www.integralist.co.uk/posts/maintainable-css-with-bem/
http://webdesign.tutsplus.com/articles/an-introduction-to-the-bem-methodology--cms-19403
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.container {
font-size: 14px;
font-family: 'Roboto', sans-serif;
color: #323231;
}
.container__aside {
position: absolute;
top: 0;
left: 0;
width: 300px;
height: 100%;
overflow: auto;
background: #f9f9f9;
border-right: 1px solid #ddd;
}
.container__aside__update {
border-bottom: 1px solid #ddd;
}
.container__aside__update:hover {
background: #fff;
cursor: pointer;
}
.container__main {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 300px;
overflow: auto;
}
.account-header {
height: 40px;
background: #00A0B0;
}
.account-header__link {
margin: 5px;
line-height: 40px;
font-family: 'Lato', sans-serif;
font-size: 0.9em;
color: #323231;
text-decoration: none;
}
.account-header__link:hover {
text-decoration: underline;
}
.account-header__link--counter {
padding: 2px 5px;
background: #cc333f;
border-radius: 5px;
color: #fff;
}
.account-header__avatar {
height: 30px;
margin: 5px;
float: right;
}
.search-bar {
height: 40px;
padding: 5px;
font-size: 0.9em;
border-bottom: 1px solid #ddd;
}
.search-bar__input {
border: none;
height: 20px;
width: 250px;
margin: 5px 0;
background: #f9f9f9;
}
.search-bar__button {
height: 20px;
width: 30px;
padding: 1px 5px;
margin: 5px 0;
border: none;
border-radius: 3px;
float: right;
background: #00a0b0;
}
.media {
overflow: hidden;
zoom: 1;
}
.media__avatar {
width: 50px;
float: left;
margin: 10px;
}
.media__avatar--big {
width: 80px;
margin: 0 10px 0 0;
}
.media__avatar--circle {
background: #ddd;
width: 30px;
border-radius: 15px;
margin: 5px;
}
.media__body {
}
.thread {
width: 600px;
margin: 60px auto;
}
.thread__likes {
height: 40px;
overflow: hidden;
margin-bottom: 40px;
}
.thread__likes__avatar {
background: #ddd;
float: left;
width: 30px;
border-radius: 15px;
margin: 5px;
}
.thread__likes__more-counter {
display: inline-block;
float: left;
background: #ddd;
color: #323231;
width: 30px;
line-height: 30px;
border-radius: 15px;
margin: 5px;
font-size: 0.8em;
text-align: center;
text-decoration: none;
}
.thread__likes__like-button {
display: inline-block;
float: right;
background: #cc333f;
color: #fafafa;
line-height: 30px;
border-radius: 3px;
line-height: 20px;
padding: 5px;
margin: 5px;
text-decoration: none;
}
.thread__header {
font-family: 'Lato', sans-serif;
font-weight: 300;
font-size: 2.5em;
}
.thread__posted-by {
height: 40px;
overflow: hidden;
margin-bottom: 40px;
}
.thread__content {
font-size: 16px;
line-height: 1.4em;
}
.thread__image {
width: 100%;
border-radius: 5px;
margin: 20px 0;
}
.thread__comments {
margin-top: 60px;
padding: 10px;
border-top: 1px solid #ddd;
}
.thread__comments__commentbox__avatar {
width: 50px;
margin: 10px;
}
.thread__comments__commentbox__input {
border: 1px solid #ddd;
height: 50px;
width: 506px;
margin: 10px 0;
}
.thread__comments__commentbox__submit {
display: inline-block;
border: none;
float: right;
background: #cc333f;
color: #fafafa;
line-height: 30px;
border-radius: 3px;
line-height: 20px;
padding: 5px;
text-decoration: none;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment