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

              
                <h2>标签(选项卡)</h2>
<p>单击选项卡菜单内的按钮:</p>
<!-- 选项卡链接 -->
<div class="tab">
  <button class="tablinks" onclick="openCity(event, 'London')">London</button>
  <button class="tablinks" onclick="openCity(event, 'Paris')">Paris</button>
  <button class="tablinks" onclick="openCity(event, 'Tokyo')">Tokyo</button>
</div>

<!-- 选项卡内容 -->
<div id="London" class="tabcontent" style="display:block;">
  <h3>London</h3>
  <p>London is the capital city of England.</p>
</div>

<div id="Paris" class="tabcontent">
  <h3>Paris</h3>
  <p>Paris is the capital of France.</p>
</div>

<div id="Tokyo" class="tabcontent">
  <h3>Tokyo</h3>
  <p>Tokyo is the capital of Japan.</p>
</div>
              
            
!

CSS

              
                /* 设置选项卡的样式 */
.tab {
  overflow: hidden;
  border: 1px solid #ccc;
  background-color: #f1f1f1;
}

/* 设置用于打开选项卡内容的按钮的样式 */
.tab button {
  background-color: inherit;
  float: left;
  border: none;
  outline: none;
  cursor: pointer;
  padding: 14px 16px;
  transition: 0.3s;
}

/* 更改悬停按钮的背景色 */
.tab button:hover {
  background-color: #ddd;
}

/* 创建活动/当前tablink类 */
.tab button.active {
  background-color: #ccc;
}

/* 设置选项卡内容的样式 */
.tabcontent {
  display: none;
  padding: 6px 12px;
  border: 1px solid #ccc;
  border-top: none;
  /*如果要淡入标签内容,请添加以下 CSS*/
  animation: fadeEffect 1s; /* 褪色效果需要1秒 */
}
/* 从零变为完全不透明度 */
@keyframes fadeEffect {
  from {opacity: 0;}
  to {opacity: 1;}
}
              
            
!

JS

              
                function openCity(evt, cityName) {
  // 声明所有变量
  var i, tabcontent, tablinks;

  // 使用class=“tabcontent”获取所有元素并隐藏它们
  tabcontent = document.getElementsByClassName("tabcontent");
  for (i = 0; i < tabcontent.length; i++) {
    tabcontent[i].style.display = "none";
  }

  // 使用class=“tablinks”获取所有元素并删除类“active”
  tablinks = document.getElementsByClassName("tablinks");
  for (i = 0; i < tablinks.length; i++) {
    tablinks[i].className = tablinks[i].className.replace(" active", "");
  }

  // 显示当前选项卡,并向打开该选项卡的按钮添加“活动”类
  document.getElementById(cityName).style.display = "block";
  evt.currentTarget.className += " active";
}
              
            
!
999px

Console