【问题标题】:Squish table to make it responsive css挤压表以使其响应 css
【发布时间】:2017-11-14 16:28:44
【问题描述】:

我想让我的表格响应我正在使用的应用程序。我已经尝试了所有不同的方法,比如让它随着窗口大小的减小而滚动。但我想有一种方法可以让桌子挤压或挤压以适应窗口的大小。请找到我的代码。希望我能尽快找到答案!

.buttonListContainer {
  position: fixed;
  top: 8.2%;
}

.buttonlistcontext {
  position: fixed;
  border: 0.1px solid #ddd;
  margin-top: 1px;
  background-color: transparent;
  margin: 0;
  padding: 0;
  top: 0;
  left: 0;
}
<div class="buttonListContainer" style="overflow:auto;margin-top:0;">
  <table id="buttonList" class="buttonlistcontext" style="visibility:hidden;">
    <tr>

      <!-- the spike count -->
      <td>
        <font size="2">Eventcount</font>: <input type="text" id="EventCount" style="width:40px;text-align:center;" disabled></td>
      <td><button style="cursor:pointer" onclick="reset()"><font size="2">Reset</font></button></td>

      <!-- the jump to very beginning button -->
      <td><input type="image" id="btn01" style="height:15px;width:15px;" src="images/play_first.png" onclick="jump_firstFrame();" />

        <!-- the play back button -->
        <input type="image" id="btn02" style="height:15px;width:15px;" src="images/play_back2.png" onclick="playBack();" />

        <!-- the go back button -->
        <input type="image" id="btn03" style="height:15px;width:15px;" src="images/play_back.png" onclick="go_back();" />

        <!-- the stop button -->
        <input type="image" id="btn07" style="height:15px;width:15px;" src="images/stop.png" onclick="animationFlag = 0; cancelAnimationFrame(myAnimation);" />

        <!-- the go forward button -->
        <input type="image" id="btn04" style="height:15px;width:15px;" src="images/play_fwd.png" onclick="go_forward();" />

        <!-- the play forward button -->
        <input type="image" id="btn05" style="height:15px;width:15px;" src="images/play_forward2.png" onclick="play();" />

        <!-- the jump to last button -->
        <input type="image" id="btn06" style="height:15px;width:15px;" src="images/play_last.png" onclick="jump_lastFrame();" /></td>

      <!-- the speed buttons -->
      <td>
        <font size="2">Speed</font>: x<select name="PlaySpeed" id="PlaySpeed" onchange="Speed(this.value);">
                    <option value= "1">1</option>
                    <option value= "5">5</option>
                    <option value= "10" selected="selected">10</option>
                    <option value= "50">50</option>
                    <option value= "100">100</option>
                    <option value= "200">200</option>

                </select>
      </td>

      <!-- Wall color drop-down list -->
      <td>
        <font size="2">Wall color</font>: <select id="WallColor" style="background-color: #CCFFCC" onchange="wallColor(this.value);">
                    <option value="1" style="background-color: #F0F0F0">Silver gray</option>
                    <option value="2" style="background-color: #CCFFCC" selected="selected">Mint green</option>
                    <option value="3" style="background-color: #FCFBE3">Vanilla cream</option>
                    <option value="4" style="background-color: #d5e8f4">Water blue</option>
                </select>
      </td>

      <!-- the scale up button -->
      <td>
        <font size="2">Sensitivity</font>: </td>
      <td><input type="image" id="btn08" style="height:15px;width:15px;" src="images/scale_up.png" onclick="sensitivity_Up();" /></td>
      <td><input type="image" id="btn09" style="height:15px;width:15px;" src="images/scale_down.png" onclick="sensitivity_Down();" /></td>

      <!-- the Montage buttons -->
      <td>
        <font size="2">Montage</font>: <select name="MontageSwap" id="MontageSwap" onchange="montageSwap(this.value);">
                    <option value= "1" selected="selected">Common Average</option>
                    <option value= "2">CII</option>
                    <option value= "3">Bipolar</option>
                </select>
      </td>


      <td>
        <!-- <button id="filterBtn" style = "cursor:pointer" onclick="filter()" ><font size="2">Filter</font></button> -->
        <a href="javascript:void(0)" onclick="filter()">
          <font size="2">Filter</font>
        </a>
      </td>

      <!-- the line cursor -->
      <td><input type="checkbox" id="LineCursor" onclick="lineCursorFlag=this.checked;draw_TeeChart()" checked/>
        <font size="2">Line cursor</font>
      </td>

      <!-- the pink bars -->
      <td><input type="checkbox" id="BGbar" onclick="BGbarFlag=this.checked;draw_TeeChart()" checked/>
        <font size="2">Highlights</font>
      </td>

      <!-- the Time interval -->
      <td>
        <font size="2">Time interval</font>: <select name="TimeInterval" id="timeIntervalSelect" onchange="timeInterval=this.value*fs;draw_TeeChart()">
                    <option value= 5>5 sec</option>
                    <option value= 10 selected="selected">10 sec</option>
                    <option value= 20>20 sec</option>
                </select>
      </td>

      <td>
        <button id="modalBtn-pre" style="cursor:pointer" onclick="CGI()"><font size="2">Pre-annotation</font></button>
      </td>
    </tr>

  </table>
</div>

【问题讨论】:

  • 有一张桌子,你会受到严重阻碍,所以一些一般性的提示... 1)摆脱桌子进行布局。 2)摆脱表格进行布局。 3) 用更现代和语义化的东西替换过时的font 标签...label 4) 看看fieldset 是否在任何地方都能满足您的需求。 5) 看看用div 分组你的控件/标签对是否有意义。 6) 查看flex-box 和其他选项。 7) 调查媒体查询如何提高响应能力。

标签: html css responsive-design responsive responsive-images


【解决方案1】:

您可以看看将bootstrap 添加到您的项目中。这可以为您节省大量时间和精力。 Bootstrap 非常适合编写响应式代码。

如果你添加了bootstrap,只需执行以下操作即可在移动设备上实现表格效果:

<div class="table-responsive">
    <table class="table">
        ....
    <table>
</div>

这将为您提供移动设备上的可滚动表格。如果您不想走引导路线,可以尝试使用上面的 HTML 进行以下操作:

<style>

@media screen and (max-width: 767px){
    .table-responsive {
        width: 100%;
        margin-bottom: 15px;
        overflow-y: hidden;
        -ms-overflow-style: -ms-autohiding-scrollbar;
        border: 1px solid #ddd;
    }
}

.table-responsive {
    min-height: .01%;
    overflow-x: auto;
}

.table{
    width: 100%;
    max-width: 100%;
}

</style>

这应该可以解决问题。看看这个plunkr

但真的看看添加引导程序。

【讨论】:

  • 我会考虑添加引导程序。但是上面的样式并没有成功!
  • @prb_123 似乎有效。对于小于 767 像素的任何屏幕宽度,它都会垂直滚动。我添加了一个 plunkr。看看吧
  • 嗨,我试过你的设计。它完全按照 plunkr 中所示的方式工作。但我想要的只是它可以像挤压桌子一样工作。如下文所示css-tricks.com/accessible-simple-responsive-tables
  • 好吧,我明白了。它应该默认挤压。给你的表格一个 100% 的宽度,并用百分比而不是像素来处理你的 宽度。
  • 酷,这很有效。但我必须绞尽脑汁才能调整位置。有没有一种简单的方法可以在不知道容器宽度的情况下将像素设置为百分比?!!
【解决方案2】:

嗯,要让它响应,你需要做重大的重新设计,使用bootstrap,或flexbox,或其他东西。

但是您仍然可以拥有一个响应式表格。将以下代码添加到您的 CSS 中,应该可以工作:

table {
    display: block;
}
tr {
    display: block;
}
td {
    display: inline-block;
}

如果您不喜欢它的外观,但仍想为桌面维护表格布局并为移动设备提供响应式内容,这里还有一个技巧。您有桌面的正常表格布局,对于窗口宽度小于 900 像素的手机和桌面,它将垂直堆叠:

@media (max-width: 900px) {
    table {
        display: block;
    }
    tr {
        display: block;
    }
    td {
        display: block;
    }
}

编辑:对于“挤压”效果,您可以这样做:

@media (max-width: 900px) {
    table {
        display: block;
    }
    tr {
        display: block;
    }
    td {
        display: inline-block;
        width: 32%;/* to have 3 columns */
    }
}

编辑 2:这是使用最后一次编辑的demo。需要注意的两件事:

  1. 在“td”中添加了box-sizing: border-box;
  2. 由于我们使用“display: inline-block;”,为了让 inline-block 按需要工作,必须删除“td”之间的所有空格。这是一个例子:

这个:

<td>
    cell1
</td>
<td>
    cell2
</td>

应改为:

<td>
    cell1
</td><td>
    cell2
</td>

【讨论】:

  • 我们可以根据文章中显示的屏幕大小来挤压桌子吗css-tricks.com/accessible-simple-responsive-tables
  • 上面的设计工作得很好,但是当屏幕尺寸减小时,所有的列往往会在页面上的其他框架上重叠到下一行。所以理想情况下,我希望桌子随着宽度的减小而缩小或挤压。
  • @prb_123 更新了我的答案
  • 是的,谢谢。我也试过了。默认情况下它仍然不会挤压。所有列项目在每个项目下都有一个。早期的解决方案看起来更好。当我说“挤压”时,请参阅文章 css-tricks.com/accessible-simple-responsive-tables
  • @prb_cm “挤压”是指 3 列,对吧?更新了我的答案,看看 Edit 2
猜你喜欢
相关资源
最近更新 更多
热门标签