html - CSS calc() 不能使 td 元素居中
问题描述
我想创建一个表格,第二列(由单个单元格表示)放在页面的中心。我正在尝试使用 calc() 函数来做到这一点,但是它不起作用。这是我的代码:
.bio {
text-align: center;
margin: 0 auto;
width: calc(100% - 200px);
}
img {
height: 200px;
}
<table cellspacing="20">
<tr>
<td>
<img src="https://placehold.it/200x200" alt="image of me">
</td>
<td class="bio">
<h1>Heading</h1>
<p>Some text</p>
</td>
</tr>
</table>
我的代码有什么问题?
解决方案
table {
display: flex;
justify-content: center;
text-align: center;
}
img {
height: 200px;
position: absolute;
left: 0;
top: 0;
}
<table cellspacing="20">
<tr>
<td>
<img src="https://placehold.it/200x200" alt="image of me">
</td>
<td class="bio">
<h1>Heading</h1>
<p>Some text</p>
</td>
</tr>
</table>
推荐阅读
- java - 如何创建独特的、复杂的 Xpath 来查找 textarea 标签?
- java - Hibernate:插入集合时为每个关系记录创建一个唯一的 GenerateValue
- mysql - 获取 php 语言的平均小时数
- ssl - SSL 证书续订
- javascript - 如何为服务器和客户端创建单独的项目?(快递和js)
- java - 理解dinic算法的问题?
- swift - 以秒为单位的 Swift 倒数计时器,每分钟更新一次标签
- python - Seaborn Countplot 中的布尔掩码
- python - 使用 Python 诗歌的安装后脚本
- python - 如何在列表理解中增加变量