<body>
<!--用display:table-cell?無(wú)法實(shí)現(xiàn)居中,我看別人能,同樣的代碼不知道為什么我不行?-->
<style>
????*?{
????????margin:?0;
????????padding:?0;
????????border:?0;
????????list-style:?none;
????}
????div?{
????????display:?table-cell;
????????width:?400px;
????????height:?450px;
????????border:?10px?solid?deeppink;
????????text-align:?center;
????????vertical-align:?middle;
????????/*box-sizing:?content-box;*/
????}
????div?img?{
????????vertical-align:?middle;
????????border:?0;
????}
</style>
<div?class="img_wrap">
????<img?src="laoshi2.png">
</div>
<!--以下用表格能實(shí)現(xiàn)垂直居中-->
<style>
????table?{
????????border-collapse:?collapse;
????}
????td?{
????????border:?10px?solid?deeppink;
????????vertical-align:?middle;
????????width:?400px;
????????height:?450px;
????????text-align:?center;
????}
????td?img?{
????????vertical-align:?middle;
????}
</style>
<table>
????<tr>
????????<td><img?src="laoshi2.png"></td>
????</tr>
</table>
</body>
3 回答

我家在玉堆
TA貢獻(xiàn)5條經(jīng)驗(yàn) 獲得超4個(gè)贊
事隔多天,再次想到這個(gè)問(wèn)題,自己解決了,代碼看起來(lái)是沒(méi)有問(wèn)題的!只不過(guò)是空白字符影響了居中的
<div?class="img_wrap"><img?src="laoshi2.png"></div>
換成這樣寫(xiě),或者讓font-size:0;
添加回答
舉報(bào)
0/150
提交
取消