当前位置: 首页 > 知识库问答 >
问题:

如何只用CSS制作标签?[副本]

利永年
2023-03-14

我希望制作一个像jQuery标签一样的标签系统,用户可以在不同的面板之间切换以查看不同的内容:

但是,我需要在不使用javascript的情况下完成这一工作,以便没有启用javascript的用户可以轻松地使用该站点。此外,我希望避免导航到不同的静态HTML页面,每个页面对应于“tab”具有不同的样式。有什么好方法来解决这个问题?

共有1个答案

曾山
2023-03-14
div#holder
    input[type="radio"]
    div.content-holder
        label
        div.tab-content (all your tab content goes here)
    input[type="radio"]
    ... keep repeating
input[type="radio"] {
    position: absolute;
    left: -100%;
    top: -100%;
    height: 0;
    display: none;
}
<label for="radioInputId1">tab title</label>
input[type="radio"] + div.content-holder > label {
    display: inline-block;
    float: left;
    height: 35px;
    width: 33%; /* or whatever width you want */
}
input[type="radio"] + div.content-holder > div.tab-content {
    display: none;
    position: absolute;
    top: 65px;        /* this depends on your label height */
    width: 100%;
}
input[type="radio"]:checked + div.content-holder > div.tab-content {
    display: block;
}
#holder {
  border: solid 1px black;
  display: block;
  height: 500px;
  position: relative;
  width: 600px;
}
p {
  margin: 5px 0 0 5px;
}
input[type="radio"] {
  display: none;
  height: 0;
  left: -100%;
  position: absolute;
  top: -100%;
}
input[type="radio"] + div.content-holder > label {
  background-color: #7BE;
  border-radius: 2px;
  color: #333;
  display: inline-block;
  float: left;
  height: 35px;
  margin: 5px 0 0 2px;
  padding: 15px 0 0 0;
  text-align: center;
  width: 33%;
}
input[type="radio"] + div.content-holder > div {
  display: none;
  position: absolute;
  text-align: center;
  top: 65px;
  width: 100%;
}
input[type="radio"]:checked + div.content-holder > div {
  display: block;
}
input[type="radio"]:checked + div.content-holder > label {
  background-color: #B1CF6F;
}
img {
  left: 0;
  margin: 15px auto auto auto;
  position: absolute;
  right: 0;
}
html lang-html prettyprint-override"><div id="holder">
  <input type="radio" name="tabs" value="1" id="check1" checked>
  <div class="content-holder">
    <label for="check1">one</label>
    <div class="tab-content">
      <p>All my content for the first tab goes here.</p>
    </div>
  </div>
  <input type="radio" name="tabs" value="2" id="check2">
  <div class="content-holder">
    <label for="check2">two</label>
    <div class="tab-content">
      <h2>You can put whatever you want in your tabs!</h2>
      <p>Any content, anywhere!</p>
      <p>
        Remember, though, they're absolutely positioned.
        This means they position themselves relative to
        their parent, div#holder, which is relatively positioned
      </p>
    </div>
  </div>
  <input type="radio" name="tabs" value="3" id="check3">
  <div class="content-holder">
    <label for="check3">three</label>
    <div class="tab-content">
      <p>
        And maybe I want a picture of a nice cat in my third tab!
      </p>
      <img src="http://i.stack.imgur.com/Bgaea.jpg">
    </div>
  </div>
</div>
 类似资料:
  • 我尝试用html、css、JavaScript制作切换标签。 这是我的代码,我试过了。 null null 但我想用仅有的HTML和CSS来制作这个函数。所以我就这样试着。但它不起作用。 null null 请帮帮我.提前谢谢你。

  • 如果将标记放置在块布局和flex布局项中,则其行为似乎有所不同: 第一个(标有绿色背景)的大小由父的宽度(页面宽度)决定。但是放置在flex容器中的第二个似乎具有最大宽度,并且生成超过页面宽度的内容。只有当有很长的单词时才会发生这种情况。有什么方法可以正确限制第二个的宽度,而不需要像显式指定它或通过)删除超过的文本那样的黑客攻击?我已经尝试了但它没有任何区别:(

  • 编辑我只想通过XML文件包括字体。

  • 我想把我的应用程序的标签放到中心。默认情况下,它向左对齐。 标签是该隐这个词, 我怎么能那么做?下面是AndroidManifest.xml的代码:

  • 我正在更新一个站点,目前有四个框,作为按钮在一个行;只不过他们用的是图像图。我想把它转换成一个CSS解决方案,这样它就不会有那么多的排泄,而且更容易访问,更友好。这样的事情怎么能做?我知道可以垂直做,但可以水平做.... 这是一个艺术家表演的它现在的样子。尺寸不是很准确,但你可以得到对角线的想法...

  • 本文向大家介绍ThinkPHP标签制作教程,包括了ThinkPHP标签制作教程的使用技巧和注意事项,需要的朋友参考一下 本文以实例讲解了ThinkPHP标签的制作方法,对于ThinkPHP的初学者或者开发人员都有一定的借鉴价值。 一般来说,ThinkPHP的默认标签解析器在Lib/Template/TagLib/TagLibCx.class(2.1版本位于ThinkPHP/Lib/Think/Te