html - CSS - 表格单元格 - 最小宽度 - 百分比和像素 : How to solve this?

标签 html css html-table

有一些类似的问题,但到目前为止我没有找到满意的答案。我有一个像示例中那样的响应表(实际上是 WordPress 管理员)。

HTML 只能在一定程度上进行更改 - 我必须使用表格。我希望单元格具有以像素为单位的最小宽度和以百分比为单位的最小宽度。

像这样:

.input-cell {
    min-width:40%;
    min-width:200px;
}

只有第二个属性会采取行动,因此这无济于事。更糟的是min-width无论天气如何,我都无法使用表格单元格 table-layout:fixedtable-layout:auto; .

以下示例演示了带有普通 width 的表风格。

table {
   width:100%;
   table-layout:auto;
}

.input-cell {
   width:40%;
}

textarea, input {
  width:95%;
}
<table>
<thead>
    <tr valign="top">
        <th scope="row">Setting</th>
        <th scope="row">Value</th>
        <th scope="row">Beschreibung</th>
        <th scope="row">ID</th>
    </tr>
</thead>
<tbody>
<tr valign="top">
  <td valign="top">Post Widget: Output callbacks</td>
  <td valign="top" class="input-cell">
    <textarea id="foo" name="bar" rows="7">Lorem ipsum ...</textarea>
  </td>
  <td class="description" valign="top">Lorem ipsum dolor sit amet.</td>
  <td class="cis_field_id" valign="top">master_cum_esse_sunc_veniat</td>
</tr>
<tr valign="top">
  <td valign="top">Post Widget: Output callbacks</td>
  <td valign="top" class="input-cell">
    <input type="text" name="lorem" id="aliquot" value="abc" />
  </td>
  <td class="description" valign="top">Lorem ipsum dolor sit amet.</td>
  <td class="cis_field_id" valign="top">master_cum_esse_sunc_veniat</td>
  </tr>
</tbody>
</table>

有什么CSS方法可以实现我想要的吗?

最佳答案

如果您添加一个 div 作为 input-cell 的直接子级并指定 min-width: 40vw(请注意我我正在使用 40vw 视口(viewport)宽度单位),然后在 divtextarea 之间添加另一个元素,或者就像我在这里所做的那样,给 textarea min-width: 200px,你的最小宽度要求都满足了。

Fiddle demo

堆栈片段

table {
  width: 100%;
  table-layout: auto;
}

.input-cell {
  width: 40%;
}

.input-cell > div {
  min-width: 40vw;
  border: 1px solid red;
}

textarea,
input {
  width: 95%;
  min-width: 200px;
}
<table>
  <thead>
    <tr valign="top">
      <th scope="row">Setting</th>
      <th scope="row">Value</th>
      <th scope="row">Beschreibung</th>
      <th scope="row">ID</th>
    </tr>
  </thead>
  <tbody>
    <tr valign="top">
      <td valign="top">Post Widget: Output callbacks</td>
      <td valign="top" class="input-cell">
        <div>
          <textarea id="foo" name="bar" rows="7">Lorem ipsum ...</textarea>
        </div>
      </td>
      <td class="description" valign="top">Lorem ipsum dolor sit amet.</td>
      <td class="cis_field_id" valign="top">master_cum_esse_sunc_veniat</td>
    </tr>
    <tr valign="top">
      <td valign="top">Post Widget: Output callbacks</td>
      <td valign="top" class="input-cell">
        <input type="text" name="lorem" id="aliquot" value="abc" />
      </td>
      <td class="description" valign="top">Lorem ipsum dolor sit amet.</td>
      <td class="cis_field_id" valign="top">master_cum_esse_sunc_veniat</td>
    </tr>
  </tbody>
</table>

关于html - CSS - 表格单元格 - 最小宽度 - 百分比和像素 : How to solve this?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44704199/

相关文章:

javascript - IE11 中的 onclick 功能不起作用

html - 我有简单的 HTML 5 代码,我试图在 chrome 上加载,但播放器显示为灰色并且没有控件在工作

javascript - jQuery 并防止函数在双击超链接时执行两次

CSS float : how to form the second row based on tallest DIV?

javascript - 悬停时的动画侧面菜单

css - 选择不包括第一行的表行

html - float 图像旁边的 table

html - 表格标题与表格宽度不成比例

jquery - 悬停时更改多个图像 : jquery/css/html

php - 使用选择选项从数据库中选择相关数据,php mysql