我有这个HTML代码:
<tbody>
<tr>
<td>
<canvas class="myid_templates_editor_canvas"></canvas>
<div>A lot of codes here</div>
<div>A lot of codes here</div>
</td>
</tr>
<tbody>
Run Code Online (Sandbox Code Playgroud)
我想只以中心canvas而不是其他子元素为中心td.所以我尝试了下面的CSS:
td {
text-align:center;
}
Run Code Online (Sandbox Code Playgroud)
但代码会影响其他元素<div>.我试过这段代码:
td > canvas {
text-align:center;
}
Run Code Online (Sandbox Code Playgroud)
上面的代码不是我的canvas元素的中心?我该怎么办?
设置固定width然后margin: auto,也display: block.text-align: center将使所有内容成为中心.
canvas.myid_templates_editor_canvas {
width: 200px;
margin: auto;
display: block;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
660 次 |
| 最近记录: |