html - CSS设置两列静态

标签 html css

Hello, I need help at styling the table. I want the update/delete button and its table cell to be static and hope anyone out there can help. My issue is when i stretch the table, or expand to fill in the details in other rows, the buttons and its column will expand and shrink. How do I make both buttons not expand and the the two column cells to be static/fixed.

So far I've tried position: absolute/fixed/auto and display: inline-block/auto.

我的 CSS 在这里

.button td {

    white-space: nowrap;
    position: absolute;   /*to fixed the button location*/ 

    }

.center {
    display: table-cell;
text-align: center;
}

CODE SAMPLE HERE

最佳答案

两件事:

  • 你正在应用 .button td 但是你的 .button 已经是一个 td 所以它应该只被应用 .按钮

  • 当您将 position:absolute 应用于子元素时,将 position:relative 应用于其父元素总是更好

absolute

Do not leave space for the element. Instead, position it at a specified position relative to its closest positioned ancestor or to the containing block. Absolutely positioned boxes can have margins, they do not collapse with any other margins.

更多信息 here

下面是一个片段:

.button {
  white-space: nowrap;
  position: absolute;
  /*to fixed the button location*/
}
.center {
  display: table-cell;
  text-align: center;
}
table.table {
  font-family: arial;
  font-size: small;
  word-wrap: break-word;
  table-layout: auto;
  width: 100%;
}
table.table td {
  padding: 5px;
  border: solid 1px #7f7f7f;
  white-space: nowrap;
  overflow: hidden;
  width: 125px;
  height: 25px;
  border-collapse: collapse;
  margin: 2px;
  position: relative;
}
table.table th {
  border: 1px solid #7f7f7f;
  padding: 5px;
  white-space: nowrap;
  overflow: hidden;
  width: 125px;
  height: 25px;
  font-weight: bold;
  background-color: #5C82FF;
  color: white;
}
table.table th a {
  text-decoration: none;
  text-align: center;
  padding-right: 20px;
  font-weight: bold;
  white-space: nowrap;
}
<table>
  <table id="datatable" class="table">
    <thead>
      <tr>
        <th style="display: none;">ID</th>
        <th>Name<i style="color: red">*</i>

        </th>
        <th>Contact<i style="color: red">*</i>

        </th>
        <th>Contact 2</th>
        <th>Fax</th>
        <th>Email</th>
        <th>Location<i style="color: red">*</i>

        </th>
        <th></th>
        <th></th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>
          <form:input path="name" />
        </td>
        <td>
          <form:input path="contact" />
        </td>
        <td>
          <form:input path="contact2" />
        </td>
        <td>
          <form:input path="contactfax" />
        </td>
        <td>
          <form:input path="fax" />
        </td>
        <td>
          <form:input path="location" />
        </td>
        <div class="center">
          <td class="button">
            <input type="submit" value="Update" style=" margin: 0 auto;" />
          </td>
        </div>
        <div class="center">
          <td class="button">
            <input type="submit" value="Delete" style=" margin: 0 auto;" />
          </td>
        </div>

关于html - CSS设置两列静态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30158671/

相关文章:

html - 用点填充剩余的空白(多行文本)

javascript - CSS在javascript中设置文本框的样式

php - 嵌入内容的最佳选择是什么

javascript - 带列的可折叠列表?

html - 使用多个 rowspan 时行高不正确

html - 垂直对齐 :middle property with no defined height

javascript - 如何从数据库中获取值并在单击提交按钮之前显示计算值

css - 悬停不工作

html - 如何在文本处于事件状态时在文本顶部创建一条垂直线?

javascript - 通过点击获取div id