【问题标题】:max-width and min-width scaling, is this possible?最大宽度和最小宽度缩放,这可能吗?
【发布时间】:2018-01-04 12:14:30
【问题描述】:

我想做的事

我有一个包含 3 列的表格:

  • 文字内容
  • 输入内容
  • 垫片

文本和输入必须最大 200 像素和最小 100 像素

我希望它们是 200px---200px---????px(屏幕宽度的其余部分)

我只希望它们在屏幕小于 400 像素时缩小

然后它们应该很好地缩小到 100px--100px--0px

如何做到这一点?

我试过了,但它似乎忽略了表格和 div 的最小值/最大值。

<table style="width:100%;" border="1">
  <tr>
    <td style="">
      <div style="width:10%; min-width:100px; max-width:200px; width:auto;">
        The text goes here
      </div>
    </td>
    <td style="">
      <input style="width:10%; min-width:100px; max-width:200px; width:auto;" 
             type="text" value="field is here">
    </td>
    <td style="width:80%;"></td>
  </tr>
</table>

(我使用内联样式是因为它在测试时速度更快,一旦生效就会放入 CSS)

【问题讨论】:

  • 听起来像是 flexbox 的案例..不是表格。
  • 我查看了一些 flexbox 示例,w3schools.com/css/css3_flexbox.asp 它看起来不是很敏感。你有一些响应式的例子吗?
  • Flexbox 完全响应式。
  • 我相信这一点还是你能证明它:-)
  • 如果您看过演示,您一定已经看过了。

标签: html css


【解决方案1】:

试试这个:

table {
    width: 100%;
    border: 1px solid green;
  }

  .text {
    background: yellow;
  }

  .input {
    background: pink;
  }

  .text,
  .input {
    width: 100px;
  }
  .spacer {
    background: orange;
    display: none;
  }

  @media (min-width: 400px) {
    .text,
    .input {
      width: 200px;
    }

    .spacer {
      display: table-cell;
      width: calc(100% - 400px);
    }
  }
<table border="0">
  <tr>
    <td class="text">1</td>
    <td class="input">2</td>
    <td class="spacer">3</td>
  </tr>
</table>

【讨论】:

  • 效果很好!!!非常感谢尤金阿兹!!!这正是我想要的,它适合我的所有代码。
  • 根据caniuse IE9 开始支持。
  • Eugen,我所要做的就是将你的 spacer 类添加到我的桌子上,我现在可以制作它们真是太棒了 :-) 看看...db.tt/Z6k8HHeZ20
  • @torbenrudgaard 很高兴能帮到你! :)
猜你喜欢
  • 2012-11-13
  • 1970-01-01
  • 2013-05-14
  • 1970-01-01
  • 2011-10-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多