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.

+ add another resource

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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.

+ add another resource

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

            
              <div id="wrap" class="hover">
  <header class="header">
    <h1>Hover/Touch Switcher</h1>
    
    <div class="switcher">
       <p>Hover or Touch Device?</p>
      <a href="#" class="touch" title="Touch list"><i class="fa fa-hand-o-up"></i> Touch</i></a>
      <a href="#" class="hover" title="Hover Grid"><i class="fa fa-location-arrow"></i> Hover</a>
    </div>
  </header>
  
  <div class="main">
    
    <p>Here we see an example of a switcher for users to dictate their preference of hover or touch. This helps if you start with a hover-first approach.</p>

      <p>On smaller screens, the selector is in the header, playing the odds that more small screens are touch devices, though certainly not always the case. Otherwise it will be in the footer, where larger screens can scroll to it easier or see it on default. </p>
   
    <p>In this example, the page starts as <code>:hover</code> enabled. Users can change the prefence to touch. On change, the page .wrap container will change the class to either touch or hover. You could always start with touch first for a more conservative approach. </p>
    
    <p>We can even increase the size of our link hit area for the touch selector to accomidate larger finger sizes.</p>
    
    <h2 class="current">Current Prefence: hover</h2>
  </div>
  
  <footer class="footer">
    <p>This site loves cats. &copy; 2013&ndash;2014</p>
  </footer>
 </div>
            
          
!
            
              @import "compass/css3";

.switcher {
  text-align: center;
  padding-top: 1em;
  @media screen and (min-width:34em){
    float: right;
    text-align: right;
    padding-top: 0;
  }
  @media screen and (min-width: 40em){
    position: absolute;
    bottom: 2em;
    border-top: 1px solid #333;
    padding-top: 1em;
    width: 50%;
    margin: 0 auto;
    left: 25%;
    text-align: center;
  }
  p {
    font-size: 0.875em;
    color: #333;
    position: absolute;
    left: -9999px;
    @media screen and (min-width: 40em){
     position: static;
    }
  }
  a {
    background: #666;
    text-decoration: none;
    color: #fff;
    padding: 10px;
    margin-right: 10px;
    display: inline-block;
    @include transition;
    .touch & {
       padding: 20px 15px;
    }
    .hover &:hover, .hover &:focus {
      outline: 10px solid black;
    }
  }
}

#wrap {
  max-width: 45em;
  margin: 0 auto;
  position: relative;
}

.header {
  padding: 1em;
  background: rgba(0,0,0,0.5);
  &:before, &:after {
    content: " ";
    display: table;
  }
  &:after {
      clear: both;
  }
}

.main {
  min-height: 180px;
  padding: 1em;
  background: rgba(0,0,0,0.3);
  border-top: 5px solid #000;
  border-bottom: 5px solid #000;
}

.footer {
  padding: 1em;
  background: rgba(0,0,0,0.5);
  text-align: center;
  @media screen and (min-width: 40em){
   padding-bottom: 8em; 
  }
}

p {
  margin-bottom: 1em;
}

h1 {
  font-size: 2em;
  text-align: center;
   @media screen and (min-width:34em){
    float: left;
    text-align: left;
  }
   @media screen and (min-width:40em){
    float: none;
  }
}

h2 {
  margin-bottom: 1em;
  font-weight: bold;
}

body {
  line-height: 1.4;
}
            
          
!
            
              $(document).on('click', 'div.switcher a', function(e) {
	var wrapClass = $(this).attr('class');
	$('#wrap').removeClass().addClass(wrapClass);
	e.preventDefault();
  $('.current').html('<h2>Current Prefence: '+wrapClass+'</h2>');
});

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console