我怎样才能将div置于绝对位置td

时间:2017-04-12 09:53:04

标签: html css

GooD早上, 我试图将div放在td中心。 对于我的td,我用相对定义了一个位置,而div的位置是绝对的。 我怎样才能将div放在中心而不去除极限?

2 个答案:

答案 0 :(得分:3)



td{
            position: relative;
            width:100px;
            height:100px;
            border:1px solid grey;
        }
        div{
            position: absolute;
            width:70px;
            height:70px;
            border:1px solid green;
            right: 15px;
            bottom:15px;
        }

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
    <tr>
    <td><div></div></td>
    </tr>
</table>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

我认为这会对您有所帮助,它会使div垂直和水平

居中

td {
  background-color: red;
  position: relative;
  height: 150px;
  width: 150px;
}

div {
  position: absolute;
  background-color: blue;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}
<table>
  <tr>
    <td>
      <div>
        some contents
      </div>
    </td>
  </tr>
</table>

相关问题