Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="controls"> 
  <label for="dir">dir:</label>
  <select id="dir">
    <option value="ltr">ltr</option>
    <option value="rtl">rtl</option>
  </select>
</div>
<div id="wrapper">
  <div class="media" data-direction="row">
    <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/182774/blueberry-cheesecake.jpg" alt="蓝莓芝士蛋糕" class="media__object">
    <div class="media__body">
      <h3 class="media__heading">蓝莓芝士蛋糕</h3>
      <p>食谱描述的地方。</p>
    </div>
  </div>

  <div class="media" data-direction="row-reverse">
    <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/182774/blueberry-cheesecake.jpg" alt="蓝莓芝士蛋糕" class="media__object">
    <div class="media__body">
      <h3 class="media__heading">蓝莓芝士蛋糕</h3>
      <p>食谱描述的地方。</p>
    </div>
  </div>
</div>
              
            
!

CSS

              
                
body {
   color: #fff;
   background-color: #101010;
   width: 100vw;
   min-height: 100vh;
   display: flex;
   flex-direction: column;
   align-items: center;
   padding: 6vh;
    margin: 0;
    box-sizing: border-box;
 }

.controls {
  margin: 0;
  padding: .5em 2em 1em 2em;
  border-bottom: 1px solid #666;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bgcolor);
  color: var(--color)
}
.controls select {
  margin-right: 1.25rem;
  color: #2f4f4f;
  font-size: 1.2rem;
}

.media {
  background: #2196F3;
  box-shadow: 0 3px 10px 0 rgba(33, 149, 243, 0.64);
  padding: 2vh;
  margin-bottom: 2.5rem;
  border-radius: 10px;
  min-width: 50vw;
  display: flex;
  position: relative;
  
  h3 {
    font-size: 24px;
    font-weight: bold;
    margin-top: 0;
    margin-bottom: 0.5rem;
  }
  
  img {
    width: 10vw;
    height: 10vw;
    border-radius: 50%;
    margin-right: 2vw;
    border: 1px solid #a0161694;
    box-shadow: inset 2vh 2vh 2vh rgba(203, 32, 32, 0.75);
  }
  
  &::before {
    content: attr(data-direction);
    font-size: 2vw;
    padding: 2vh 4vh;
    background: rgba(201, 236, 24, 0.5);
    border-radius: 8px 0 0 8px;
    position: absolute;
    right: 100%;
    top: 50%;
    transform: translate(0, -50%);
    white-space: nowrap;
  }
  
  &[data-direction="row"] {
    margin-top: 60px;
  }
  
  &[data-direction="row-reverse"] {
    flex-direction: row-reverse;
    
    img {
      margin-right: 0;
      margin-left: 2vw;
    }
  }
}

[dir="rtl"] .media {
  &[data-direction="row"] {    
    img {
      margin-left: 2vw;
      margin-right: 0;
    }
  }
  
  &[data-direction="row-reverse"] {    
    img {
      margin-right: 2vw;
      margin-left: 0;
    }
  }
}

              
            
!

JS

              
                const dirSelector = document.getElementById('dir');
const wrapper = document.getElementById('wrapper');
dirSelector.addEventListener('change', (e) => {
  console.log('====> dir:', e.target.value)
  wrapper.setAttribute('dir', e.target.value)
})

              
            
!
999px

Console