内部标签

时间:2017-05-26 05:20:56

标签: html css3 tabs amp-html

我正在尝试使用此link制作标签。

我能够做到。但是,当我进行嵌套(选项卡内容中的选项卡)时,我没有得到预期的输出。我无法自动选择内部标签(第一次运行代码时)。即,当我运行我的应用程序时,#34;标签1"被选中显示其内容示例"一个div"两个标签"标签内一个","标签二"。但我想在标签1中显示""作为选定的标签并向其显示内容"标签一个内容"

这是我的code

<amp-selector role="tablist" layout="container1" class="ampTabContainer">
  <div role="tab" class="tabButton" selected option="a">Tab one</div>
  <div role="tabpanel" class="tabContent">
    <div>one div
      <amp-selector role="tablist" layout="container" class="ampTabContainer">
        <div role="tab" class="tabButton" option="a">inside Tab one</div>
        <div role="tabpanel" class="tabContent">Tab one content... </div>
        <div role="tab" class="tabButton" option="b">Tab two</div>
        <div role="tabpanel" class="tabContent">Tab two content... </div>
      </amp-selector>
    </div>
  </div>
  <div role="tab" class="tabButton" option="b">Tab two</div>
  <div role="tabpanel" class="tabContent">Tab two content... </div>
</amp-selector> 

运行我的应用程序时预期输出如下所示

Expected output

1 个答案:

答案 0 :(得分:1)

根据documentation,您无法嵌套放大器选择器

  

amp-selector不能包含任何嵌套的amp-selector控件。

您可以使用单选按钮创建选项卡,并在使用所选属性和css不透明度之间切换

&#13;
&#13;
* {
  box-sizing: border-box;
}



::selection {
  background-color: #4EC6DE;
}

.tabbed {
  width: 700px;
  margin: 50px auto;
}

.tabbed > input {
  display: none;
}

.tabbed > label {
  display: block;
  float: left;
  padding: 12px 20px;
  margin-right: 5px;
  cursor: pointer;
}

.tabbed > label:hover,
.tabbed > input:checked + label {
  background: #4EC6DE;
}

.tabs {
  clear: both;
  perspective: 600px;
}

.tabs > div {
  width: 700px;
  position: absolute;
  border: 2px solid #4EC6DE;
  padding: 10px 30px 40px;
  line-height: 1.4em;
  opacity: 0;
  z-index: 0;
}

#tab-nav-1:checked ~ .tabs > div:nth-of-type(1),
#tab-nav-2:checked ~ .tabs > div:nth-of-type(2),
#tab-nav-3:checked ~ .tabs > div:nth-of-type(3),
#tab-nav-4:checked ~ .tabs > div:nth-of-type(4){
  opacity: 1;
  z-index: 1;
}
&#13;
 <div class="tabbed">
    <input type="radio" name="tabs" id="tab-nav-1" checked>
    <label for="tab-nav-1">HTML</label>
    <input type="radio" name="tabs" id="tab-nav-2">
    <label for="tab-nav-2">CSS</label>
    <input type="radio" name="tabs" id="tab-nav-3">
    <label for="tab-nav-3">Javascript</label>
    <input type="radio" name="tabs" id="tab-nav-4">
    <label for="tab-nav-4">Output</label>
    <div class="tabs">
      <div><h2>HTML</h2><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sit amet nulla tortor, a posuere urna. Praesent urna quam, semper ut ultricies et, mollis ac elit. </p><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sit amet nulla tortor, a posuere urna. Praesent urna quam, semper ut ultricies et, mollis ac elit. Suspendisse tempor, lacus id consectetur sagittis, lorem odio dignissim nulla, a condimentum sem neque sed ligula. Maecenas id risus eros, eget porttitor metus. Quisque pellentesque neque dignissim nisl pellentesque vitae tempus urna eleifend. Nullam egestas, neque id placerat luctus, nibh velit pharetra nulla, vel pretium justo massa ut elit. Vivamus nec auctor nunc.</p></div>
      <div><h2>CSS</h2><p>Maecenas dictum, urna ut consequat condimentum, est dui commodo diam, ac pretium dui ante eu quam. Curabitur posuere metus nec tellus venenatis placerat. Ut egestas neque in odio vulputate gravida. In at justo ac est laoreet eleifend vel quis arcu. Aliquam erat volutpat. Proin vitae vehicula neque. Nam tempus erat ac ante tincidunt tincidunt. Pellentesque eu nibh sapien. Nunc augue magna, lacinia eget congue eget, mattis id tortor. Fusce id vestibulum neque. Proin tincidunt tellus ut risus lobortis cursus. Duis sit amet urna vel sapien ullamcorper varius.</p></div>
      <div><h2>Javascript</h2><p>Duis luctus dolor ac erat luctus hendrerit. Aenean id congue magna. Proin sit amet elit vel lacus ornare dignissim imperdiet nec odio. Maecenas condimentum egestas lorem et laoreet. Donec ut leo non purus rutrum euismod vel faucibus nunc. Curabitur vel mauris nisi, vitae laoreet erat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas ipsum odio, iaculis id vulputate vitae, vestibulum at nunc. Integer non nisl lorem. Quisque lobortis congue semper. Nunc neque nisi, consequat id egestas vitae, porta vel sem.</p></div>
      <div><h2>Output</h2><p>Fusce vel eros eu lectus ultricies fermentum vestibulum adipiscing odio. Suspendisse ultricies, metus nec dapibus pharetra, quam arcu vulputate nisl, a pretium nisi velit id ante. Nunc auctor augue sit amet orci vestibulum id placerat nulla pellentesque. Duis vel quam velit. Ut auctor ipsum quis lacus semper non pretium mi dignissim. Morbi ultrices augue eget nisi hendrerit placerat. Mauris rhoncus urna quis metus congue quis condimentum risus interdum. Nam lobortis lectus et enim laoreet mattis. Integer faucibus ullamcorper erat, at rhoncus leo bibendum sed. Mauris libero urna, placerat non pretium ac, elementum et arcu. Aliquam non tellus diam, vel scelerisque odio. Etiam a quam et enim vehicula feugiat posuere at dui. Phasellus at nisl quam. Integer nisi mi, varius vitae placerat viverra, dapibus vitae massa. Nullam ut orci vitae nisi ornare aliquam in eget orci.</p></div>
    </div>
  </div>
&#13;
&#13;
&#13;

请参阅YozhEzhi codepen https://codepen.io/YozhEzhi/pen/gcLpI?editors=1100