cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              %section.container
  %article.components
    %h1 BEM Syntax Visualized
    %p Click anywhere on this window, then hit the TAB key to get started. You can also click on the components to display their class name(s), but using the TAB key is way better.
    
    %h2 Components
    .component
      %h3 .button
      %p 
        %a.button
          %span.button__text Button Text
        // lazy spacers. Don't judge me
        %br
        %br
    .component
      %h3 .list
      %ul.list
        %li.list__item List Item 1
        %li.list__item List Item 2
        %li.list__item List Item 3
  
  .component.component--no-bg
    %h3 .card
    .card
      .card__header
        .card__title Title
      .card__content 
        %p Content hia whatever 8-bit pork belly. YOLO mlkshk everyday carry, 3 wolf moon cred keffiyeh green.

        %p Juice banjo vegan intelligentsia 8-bit cronut humblebrag readymade. 
 
  .component.component--no-bg
    %h3 Real use case: Combined .card with .list and .button
    %article.card
      .card__header
        %h2.card__title B is for Block: How to BEM
      .card__content
        %ol.list.card__list
          %li.list__item
            Describe the Main Block with a word or two.
          %li.list__item 
            Describe the __element with a word or two.
          %li.list__item
            Add --modifiers if necessary.
        %a.button.button--with-icon.card__button
          %span.button__text
            Read More
          %span.button__icon
            // really, it'd just be .button__icon placed on the svg, but the tooltip won't work that way so I'm improvising
            %svg
              <use xlink:href="#icon-chevron-right" />

%p Read more about BEM in my article, <a href="http://jeremyjon.es/code/b-is-for-block-an-intro-to-the-bem-naming-convention/">B is for Block: An Intro to the BEM Naming Convention</a>



<svg style="position: absolute; width: 0; height: 0;" width="0" height="0" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<symbol id="icon-chevron-right" viewBox="0 0 1024 1024">
<title>Chevron Right</title>
<path class="path1" d="M426 256l256 256-256 256-60-60 196-196-196-196z"></path>
</symbol>
</defs>
</svg>


            
          
!
            
              // colors
$blue: #125B68;
$green: #02906b;
$salmon: #e85f5f;
$link: $green;
// easing function
$fastInEaseOut: cubic-bezier(0.000, 0, .3, 1);

%focus--glow {
    outline-color: lighten($salmon, 10);
    outline-offset: 1px;
    outline-style: auto;
    outline-width: 3px;
}


body {
  background: #e9f3f0;
  max-width: 25rem;
  margin: 0 auto;
  padding: 10px 10px 3rem;
  font-family: "ff-tisa-sans-web-pro", Trebuchet MS,Lucida Grande,Lucida Sans Unicode,Lucida Sans,Tahoma, sans-serif;
}

a {
  color: $link;
  text-decoration: none;  
}

.container {
  max-width: 25rem;
  margin: 2rem auto;
}

.container--flex {
  display: flex;
}

.component {
  padding: 1rem 1.6rem;
  margin: 2rem 0;
  background: #fff;
  box-shadow: 0 1px 1px rgba(0,0,0,.2);
  border-left: 4px solid $salmon;
}

.component--no-bg {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
}

.button {
  font-size: 1.1rem;
  padding: 0.8rem 1.8rem 1rem;
  background: $link;
  border-radius: 3px;
  cursor: pointer;
  text-align: center;
  text-transform: uppercase;
  transition: all .2s ease-out;
  text-shadow: 0 -1px 0 darken($link, 10);
  box-shadow: inset 0 -0.2rem 0 darken($link, 10);
}

.button--with-icon {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0.6rem 1.2rem 0.5rem 1.8rem;
  
}
 
.button__text {
  color: #fff;
  font-size: 1rem;
}

.button__icon svg {
  fill: #fff;
  width: 2.2rem;
  height: 2.2rem;
  position: relative;
  top: 3px;
  transition: all .2s $fastInEaseOut;
}
 
.list {
  padding-left: 1.2rem;
  margin-bottom: 1.6rem;
}

.list__item {
  margin-bottom: 0.6rem;
}

.card {
  max-width: 15rem;
  padding: 0.6rem 1.2rem 1.2rem;
  margin-bottom: 2rem;
  background: #fff;
  border-top: 4px solid lighten($link, 10);
  box-shadow: 0 1px 1px rgba(0,0,0,.2);
}

.card__header {
  padding: 0.6rem 0 0.6rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid #ddd; 
}

.card__title {
  font-size: 2rem;
  line-height: 1.3;
  font-weight: bold;
  padding: 0;
  margin: 0;
}


.button, .button__text, .button__icon, 
.card, .card__header, .card__title, .card__content, 
.list, .list__item {
  cursor: pointer;
  &:focus {
    @extend %focus--glow;
    
    & > .tooltip {
      display: block;
      opacity: 1;
      z-index: 9;
      animation: tooltipActive .5s $fastInEaseOut;
    }
  }
}

.button, .card, .list, .list__item {
  position: relative;
}

.tooltip {
  position: absolute;
  font-size: 0.95rem;
  line-height: 1.3;
  font-weight: normal;
  text-transform: none;
  text-shadow: none;
  padding: 2px 4px;
  border-radius: 3px;
  background: darken($salmon, 8);
  color: #fff;
  opacity: 0;
  display: none;
  top: 0;
  right: -5px;
  @media (min-width: 33rem) {
    left: 105%;
    right: auto;
  }
  
  transition: all .3s;
  // outline hack to cover up focus from parent element
  outline-color: darken($salmon, 8);
  outline-offset: -1px;
  outline-style: solid;
  outline-width: 5px;
  
  .tooltip__item {
    text-align: left;
    margin-bottom: 0.2rem;
    white-space: nowrap;
    
    &:last-child {
      margin-bottom: 0;
    }
  }
  
}

.card__content > .tooltip,
.button .tooltip {
  top: auto;
}

@keyframes tooltipActive {
  0% {
    opacity: 0;
    transform: translate3d(-100px, 0, 0);
  }
  35% {
    transform: translate3d(-100px, 0, 0);
  }
  60% {
    opacity: 1;
  }
  100% {
    opacity: 1;
    transform: scale(1) translate3d(0,0,0);
  }
}


            
          
!
            
                  // This pen is supposed to teach markup. All the JS does is add the HTML for the tooltips to keep the HTML panel cleaner and easier to understand.

// The tooltips themselves just work by displaying when they gain focus. CSS-only style. 

// All elements of the components have tabindex=0 set by the JS to make them focusable.
   
// The function that does all the work.
// add tooltips based on a string of a classname
function createTooltip(str) {
  var el,
      classNames, 
      classList,
      tooltip,
      tooltipItem;
  // get our elements by classname
  el = document.getElementsByClassName(str);
  
  // loop all the matching elements
  for (var i = 0; i < el.length; i++) {
    // first, set the tabindex to 0 to make it focusable
    el[i].tabIndex = 0;
    var re = /\s+/;
    classNames = el[i].className;
    if(re.test(classNames)) {
      // split the classnames
      classList = classNames.split(re);
    } else {
      // make it an array
      classList = [classNames];
    }

    // create a tooltip div
    tooltip = document.createElement('div');
    // add the class name
    tooltip.classList.add('tooltip');
    // loop through all the classnames of the element
    for (var j = 0; j < classList.length; j++) {
      // create a tooltip item
      tooltipItem = document.createElement('div');
      // add tooltip__item class name to it
      tooltipItem.classList.add('tooltip__item');
      // add the looped class name of the element as its content
      
      tooltipItem.innerHTML = '.'+classList[j];
      // append it to our tooltip element
      tooltip.appendChild(tooltipItem);
    }
    // insert the tooltip element into the original element
    el[i].insertBefore(tooltip, el[i].firstChild);
  }
}
  
// create the tooltips for each item by classname
// I could have added a class to items in the HTML like "tooltip-ize," to initiate the tooltip set-up, but I wanted to keep the html 100% clear of extraneous classes in order to keep the focus on the BEM class names.
createTooltip('button');
createTooltip('button__text');
createTooltip('button__icon');
createTooltip('card');
createTooltip('card__header');
createTooltip('card__title');
createTooltip('card__content');
createTooltip('list');
createTooltip('list__item');
            
          
!
999px
Loading ..................

Console