<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>

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;
    }
  }
}
View Compiled
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)
})
View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.