使其不因内容而垂直扩展表格单元格

时间:2018-11-14 12:34:55

标签: javascript html css vue.js

我有一个html表,我用从数据库中获取的内容填充了该表,但是我想避免一个副作用,我想避免单元格垂直扩展以适应内容,我尝试使用table-layout:fixedoverflow:hidden或为行设置max height,但这些都不起作用。

有什么主意我可以解决这个问题吗?

这是我的表格组件(使用vue):

<table class="entry_table_container" v-if="posts" style="overflow:hidden; table-layout:fixed;">
  <tr>
    <th class="entry_table_header" width="5%">Categoría</th>
    <th class="entry_table_header" width="5%">Titulo</th>
    <th class="entry_table_header" width="5%">Contenido</th>
    <th class="entry_table_header" width="5%">Imagen</th>
    <th class="entry_table_header" width="5%">Descripción</th>
    <th class="entry_table_header" width="5%">Visible</th>
    <th class="entry_table_header" width="5%">Acción</th>
  </tr>
  <tr class="row" v-for="post in posts" :key="post.id">
    <td>{{ post.postcategory.name }}</td>
    <td>{{ post.title }}</td>
    <td v-html="post.body"></td>
    <td>
      <div class="image_row_container" :style="'background-image:url('+post.image+');'"></div>
    </td>
    <td v-html="post.imageDescription"></td>
    <td class="checkbox_row" style=""><input type="checkbox" class="entry_checkbox" :checked="post.isVisible"></td>
    <td class="row_buttons_container">
      <button class="row_buttons_button boot_blue" @click="showModal({ activePostModal: 'PostUpdateModal', post: post})" type="button" title="Editar"><i class="fas fa-pencil-alt"></i></button>
      <button class="row_buttons_button boot_red" @click="showModal({ activePostModal: 'PostDeleteModal', post: post})" type="button" title="Eliminar"><i class="fas fa-trash-alt"></i></button>
    </td>
  </tr>
</table>

1 个答案:

答案 0 :(得分:0)

您可以用div包装td内容,然后设置其高度

.heightCont{
  height: 1em;
  overflow: hidden;
}
<table class="entry_table_container" v-if="posts" style="overflow:hidden; table-layout:fixed;">
  <tr>
    <th class="entry_table_header" width="5%">Categoría</th>
    <th class="entry_table_header" width="5%">Titulo</th>
    <th class="entry_table_header" width="5%">Contenido</th>
    <th class="entry_table_header" width="5%">Imagen</th>
    <th class="entry_table_header" width="5%">Descripción</th>
    <th class="entry_table_header" width="5%">Visible</th>
    <th class="entry_table_header" width="5%">Acción</th>
  </tr>
  <tr class="row" v-for="post in posts" :key="post.id">
    <td><div class="heightCont">{{ post.postcategory.name }}</div></td>
    <td><div class="heightCont">{{ post.title }}</div></td>
    <td v-html="post.body"></td>
    <td>
      <div class="image_row_container" :style="'background-image:url('+post.image+');'"></div>
    </td>
    <td v-html="post.imageDescription"></td>
    <td class="checkbox_row" style=""><input type="checkbox" class="entry_checkbox" :checked="post.isVisible"></td>
    <td class="row_buttons_container">
      <button class="row_buttons_button boot_blue" @click="showModal({ activePostModal: 'PostUpdateModal', post: post})" type="button" title="Editar"><i class="fas fa-pencil-alt"></i></button>
      <button class="row_buttons_button boot_red" @click="showModal({ activePostModal: 'PostDeleteModal', post: post})" type="button" title="Eliminar"><i class="fas fa-trash-alt"></i></button>
    </td>
  </tr>
</table>

相关问题