<div class="controls"> 
  <label for="dir">dir:</label>
  <select id="dir">
    <option value="ltr">ltr</option>
    <option value="rtl">rtl</option>
  </select>
  
  <label for="direction">direction:</label>
  <select id="direction">
    <option value="ltr">ltr</option>
    <option value="rtl">rtl</option>
  </select>

  <label for="writingmode">writing-mode:</label>
  <select id="writingmode">
    <option value="horizontal-tb">horizontal-tb</option>
    <option value="vertical-lr">vertical-lr</option>
    <option value="vertical-rl">vertical-rl</option>
  </select>
</div>

<div id="wrapper" dir="ltr" style="direction: ltr">
  <div class="block text-align">
    <h3>文本对齐(text-align)</h3>
    <p class="left">我是一行文本,使用text-align: left 左对齐, 使用text-align:right右对齐( 本行设置text-align: left)</p>
    <p class="right">我是一行文本,使用text-align: left 左对齐, 使用text-align:right右对齐( 本行设置text-align: left)</p>
  </div>
  
  <div class="block float">
    <h3>浮动布局(float)</h3>
    <div class="media">
      <div class="media__object">
        <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/182774/blueberry-cheesecake.jpg" alt="" />
      </div>
      <div class="media__body">
        <h4 class="media_heading">我是一个标题</h4>
        <p>我是一个段落,用来描述,采用了float: left布局</p>
      </div>
    </div>
    
    <div class="media media__right">
      <div class="media__object">
        <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/182774/blueberry-cheesecake.jpg" alt="" />
      </div>
      <div class="media__body">
        <h4 class="media_heading">我是一个标题</h4>
        <p>我是一个段落,用来描述,采用了float: right布局</p>
      </div>
    </div>
  </div>
  
  <div class="block">
    <h3>Flexbox布局</h3>
    <div class="flex">
      <div class="aside">Sidebar</div>
      <div class="main">Main</div>
    </div>
  </div>
  
  <div class="block">
    <h3>Grid布局</h3>
    <div class="grid">
      <div class="aside">Sidebar</div>
      <div class="main">Main</div>
    </div>
  </div>
  
  <div class="block">
    <h3>Box Alignment</h3>
    <div class="box-alignment">
      <div class="item">1</div>
      <div class="item">2</div>
      <div class="item">3</div>
    </div>
  </div>
  
  <div class="block">
    <h3>Shape</h3>
    <div class="shape">
      <img  src="https://www.footyrenders.com/render/Neymar-45.png" alt="Rabbit" />
  <p>
    Alice is feeling bored and drowsy while sitting on the riverbank with her elder sister. She then notices a talking, clothed White Rabbit with a pocket watch run past. She follows it down a rabbit hole when suddenly she falls a long way to a curious hall
    with many locked doors of all sizes.</p> 
  
  <p>She finds a small key to a door too small for her to fit through, but through it she sees an attractive garden. She then discovers a bottle on a table labelled "DRINK ME," the contents of which cause her to shrink
    too small to reach the key which she has left on the table.</p> 
  
  <p>She eats a cake with "EAT ME" written on it in currants as the chapter closes. Alice is feeling bored and drowsy while sitting on the riverbank with her elder sister. She then notices a talking,
    clothed White Rabbit with a pocket watch run past.</p> 
  <p>She follows it down a rabbit hole when suddenly she falls a long way to a curious hall with many locked doors of all sizes.</p> 
      <p>She eats a cake with "EAT ME" written on it in currants as the chapter closes. Alice is feeling bored and drowsy while sitting on the riverbank with her elder sister. She then notices a talking,
    clothed White Rabbit with a pocket watch run past.</p> 
  <p>She follows it down a rabbit hole when suddenly she falls a long way to a curious hall with many locked doors of all sizes.</p> 
    </div>
  </div>
</div>
:root {
  --bgcolor: #fff;
  --color: #333;
}
body {
  background-color: var(--bgcolor);
  color: var(--color);
  margin: 5em 2em 1em 2em;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto,
    Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  line-height: 1;
/*     letter-spacing: 0.12em; */
/*     word-spacing: 0.16em; */
/*     font-size: 200%; */
}

/* Dark mode */
@media screen and (prefers-color-scheme: dark) {
  :root {
    --color: #fff;
    --bgcolor: #101010;
  }
  a:link, a:visited {
    color: #0ff;
  }
}



/* Toggle */
/* https://adrianroselli.com/2019/08/under-engineered-toggles-too.html */

.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;
}

#wrapper {
  unicode-bidi: embed;
}

.block {
  background: #371c1c;
  box-shadow: 0 5px 10px 0 rgba(#000, 0.05);
  padding: 1rem;
  margin-bottom: 2.5rem;
  border-radius: 8px;
}

.left {
  text-align: left;
}

.right {
  text-align: right;
}

.media {
  display: flow-root;
  background: rgba(0,0,0,.5);
  box-shadow: 0 3px 10px 0 rgba(#000, 0.1);
  padding: 1rem;
  margin-bottom: 1.5rem;
  border-radius: 4px;
  
  img {
    max-width: 100%;
    border-radius: 4px;
  }
}

.media__object {
  float: left;
  width: 200px;
  margin-right: 16px;
  box-shadow: 0 3px 10px 0 rgba(#000, 0.1), inset 0 3px 10px 0 rgba(#9f0, 0.5);
  border-radius: 4px;
}

.media__right .media__object {
  float: right;
  margin-left: 16px;
}

.flex {
  display: flex;
  align-items: center;
  
  > div {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
    border-radius: 6px;
    background: rgba(0,0,0,.5);
  }
  
  .aside {
    width: 200px;
    margin-right: 20px;
  }
  
  .main {
    flex: 1;
  }
}

.grid {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 20px;
  
  > div {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
    border-radius: 6px;
    background: rgba(0,0,0,.5);
  }
}

.box-alignment {
  display: flex;
  justify-content: flex-start;
  
  > div {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
    border-radius: 6px;
    background: rgba(0,0,0,.5);
    padding: 3vh;
    
    &:not(:first-child) {
      margin-left: 20px;
    }
  }
}

.shape {
  display: flow-root;
  
  img {
    height: 300px;
    float: left;
    shape-outside:polygon(105px 202px, 67px 197px, 40px 268px, 1px 274px, -3px 253px, 30px 235px, 40px 170px, 64px 151px, 90px 143px, 99px 115px, 50px 146px, 33px 163px, 19px 142px, 29px 128px, 48px 122px, 92px 94px, 105px 59px, 114px 50px, 110px 27px, 119px 2px, 143px 3px, 176px 14px, 208px 42px, 179px 68px, 132px 283px, 119px 303px, 96px 292px, 79px 299px);
    margin-right: 20px;
  }
}
const dirSelector = document.getElementById('dir');
const directionSelector = document.getElementById('direction');
const writingModeSelector = document.getElementById('writingmode');
const wrapper = document.getElementById('wrapper')

dirSelector.addEventListener('change', (e) => {
  console.log('====> dir:', e.target.value)
  wrapper.setAttribute('dir', e.target.value)
  wrapper.style.direction=e.target.value
  directionSelector.value = e.target.value
})

directionSelector.addEventListener('change', (e) => {
  console.log('====> direction:', e.target.value)
  wrapper.setAttribute('dir', e.target.value)
  wrapper.style.direction=e.target.value
  dirSelector.value =  e.target.value
})

writingModeSelector.addEventListener('change', (e) => {
  console.log('====> writing-mode:', e.target.value)
  wrapper.style.writingMode=e.target.value
})

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.