我有一张桌子,但我不确定如何让标题可以滚动

阿尔贝托

嗨,我正在创建一个表格,我想为适用于桌面和移动设备的标题添加一个滚动选项。我之前使用滚动选项创建了菜单,并且还创建了表格,但这是我第一次组合两个不同的“类”,并且我检查了一个教程,该教程说我可以将它们与空格组合在一起,但它不起作用。拜托,知道我该怎么做吗?

<meta name="viewport" content="width=device-width, initial-scale=1">
<style>

div.tab {
overflow: hidden;
}

div.tab button {
float: left;
padding: 14px 16px;
font-size: 20px;
}

div.tabcontent {
display: none;
}

div.scrollmenu {
overflow: auto;
white-space: nowrap;
}

</style>

<div class="tab scrollmenu">
<button class="tablinks" onclick="openTable(event, 'Table Header 1')">Table Header 1</button>
<button class="tablinks" onclick="openTable(event, 'Table Header 2')">Table Header 2</button>
<button class="tablinks" onclick="openTable(event, 'Table Header 3')">Table Header 3</button>
<button class="tablinks" onclick="openTable(event, 'Table Header 4')">Table Header 4</button>
<button class="tablinks" onclick="openTable(event, 'Table Header 5')">Table Header 5</button>
<button class="tablinks" onclick="openTable(event, 'Table Header 6')">Table Header 6</button>
</div>

<div id="Table Header 1" class="tabcontent">
<h3>Table Header 1</h3>
<p>This is the Table Header for the Table number 1.</p>
</div>

<div id="Table Header 2" class="tabcontent">
<h3>Table Header 2</h3>
<p>This is the Table Header for the Table number 2.</p> 
</div>

<div id="Table Header 3" class="tabcontent">
<h3>Table Header 3</h3>
<p>This is the Table Header for the Table number 3.</p>
</div>

<div id="Table Header 4" class="tabcontent">
<h3>Table Header 4</h3>
<p>This is the Table Header for the Table number 4.</p>
</div>

<div id="Table Header 5" class="tabcontent">
<h3>Table Header 5</h3>
<p>This is the Table Header for the Table number 5.</p>
</div>

<div id="Table Header 6" class="tabcontent">
<h3>Table Header 6</h3>
<p>This is the Table Header for the Table number 6.</p>
</div>

<script>
function openTable(evt, TableName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(TableName).style.display = "block";
evt.currentTarget.className += " active";
}
</script>
巢穴

我重写了一些让我很吵的东西:

id 的值不能包含空格(空格、制表符等)。浏览器将包含空格的不合格 ID 视为空格是 ID 的一部分。

MDN 参考

我刚刚将display: flex样式添加到div.scrollmenu并且工作得很好。

function openTable(evt, TableName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(TableName).style.display = "block";
evt.currentTarget.className += " active";
}
div.tab {
  overflow: hidden;
}

div.tab button {
  float: left;
  padding: 14px 16px;
  font-size: 20px;
}

div.tabcontent {
  display: none;
}

div.scrollmenu {
  overflow: auto; /* you can change auto to overlay*/
  white-space: nowrap;
  display: flex;
}
    <div class="tab scrollmenu">
      <button class="tablinks" onclick="openTable(event, 'table-header-1')">Table Header 1</button>
      <button class="tablinks" onclick="openTable(event, 'table-header-2')">Table Header 2</button>
      <button class="tablinks" onclick="openTable(event, 'table-header-3')">Table Header 3</button>
      <button class="tablinks" onclick="openTable(event, 'table-header-4')">Table Header 4</button>
      <button class="tablinks" onclick="openTable(event, 'table-header-5')">Table Header 5</button>
      <button class="tablinks" onclick="openTable(event, 'table-header-6')">Table Header 6</button>
    </div>

    <div id="table-header-1" class="tabcontent">
      <h3>Table Header 1</h3>
      <p>This is the Table Header for the Table number 1.</p>
    </div>

    <div id="table-header-2" class="tabcontent">
      <h3>Table Header 2</h3>
      <p>This is the Table Header for the Table number 2.</p>
    </div>

    <div id="table-header-3" class="tabcontent">
      <h3>Table Header 3</h3>
      <p>This is the Table Header for the Table number 3.</p>
    </div>

    <div id="table-header-4" class="tabcontent">
      <h3>Table Header 4</h3>
      <p>This is the Table Header for the Table number 4.</p>
    </div>

    <div id="table-header-5" class="tabcontent">
      <h3>Table Header 5</h3>
      <p>This is the Table Header for the Table number 5.</p>
    </div>

    <div id="table-header-6" class="tabcontent">
      <h3>Table Header 6</h3>
      <p>This is the Table Header for the Table number 6.</p>
    </div>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

我如何退回在另一张桌子上无效的设备

如何从一张桌子获得我想要的视图结果

我可以仅使用一个标签“ tr”制作一张像这张照片的桌子吗?

一张桌子可以有多个模型吗

我如何订购另一张桌子的查询?

如何将一张桌子直接放在另一张桌子上

我可以阻止一张桌子更新吗?

我有一张桌子,我想对其进行一些预先计算并以新的形状获得桌子

我有一张桌子,我的输出结果如描述中所示

我的查询有效,但我需要进行扩展。我需要删除工会,但不确定如何进行

我有一张桌子,为什么我的中央单元格比其他单元格长

有没有一种方法可以找到从一张桌子到另一张桌子的缺失数字?(比较)

如何修复我的代码以显示一张桌子?

火鸟-自我加入一张桌子

我该如何在同一张桌子上进行双重连接

我在Excel 2007中有一张桌子,我想要一张图表

如何获得一张方形桌子?

我有一张桌子,上面有城市和人口。我想根据人口进行随机分组

我想显示一张桌子上的记录

我有一张桌子,希望我的描述中显示的结果桌子

SQL 数据库。我丢了一张桌子,我现在如何创建它?

我应该使用一张桌子还是分成两张桌子?

XSLT 为每一行创建单独的表。我如何将它们变成一张桌子?

为什么我的搜索字段在一张桌子上有效,而在另一张桌子上无效?

有一个想法,但我不确定如何去做,如果单独使用 django 就足够了?

Tcl Eval ,但我不确定

如何搭建一张桌子?

在一张桌子内,我需要有 thead、tbody 和 tfooter 吗?

我曾尝试使用 beautifulsoup 刮一张桌子,但表格中只有一行显示为输出