gpt4 book ai didi

html - CSS 垂直对齐 :middle doesn't work

转载 作者:行者123 更新时间:2023-11-28 08:07:00 25 4
gpt4 key购买 nike

CSS:

.wrap {
width: 100%;
display: table;
height:100px;
}
.wrap tr {
width:30%;
text-align: center;
vertical-align: middle;
display: table-cell;
margin: 20px;
border:1px solid black;
line-height: 100px;
}

HTML:

<table class="wrap">
<tr>
<th><h1>Design Your Bag</h1></th>
</tr>
<tr>
<th><img src="CMBlogo.gif" style="height:100px;width:100px;" alt="logo"></th>
</tr>
<tr id="right">
<th><h2><a href="#"><span class="glyphicon glyphicon-phone-alt" aria-hidden="true"></span></a>&nbsp;&nbsp;Live Help!</h2>
<h4>(202)-629-3053</h4>
<h4><a href="mailto:brian@metrologo.com" subject="Contact and Order Information">brian@metrologo.com</a></h4></th>
</tr>
</table>

问题:当我尝试在每个 tr 垂直中心制作图像和文本时,没有任何反应......我在网上搜索了很多类似的问题,并尝试使用,或“行高”,并向左浮动/右/中心。仍然无法使其正常工作...也许存在一些我没有意识到的小误解或错误..请帮助我..

最佳答案

您的表格行元素在中间垂直对齐。如果您希望整个表格在页面上垂直对齐,请执行以下操作:

html, body{ margin:0; padding:0; height:100%; width:100%; }
.wrap {
width: 100%;
display: table;
height:100px;
position:relative;
top:50%;
transform:translateY( -50% );
}
.wrap tr {
width:30%;
text-align: center;
vertical-align: middle;
display: table-cell;
margin: 20px;
border:1px solid black;
line-height: 100px;
}
<html>
<body>
<table class="wrap">
<tr>
<th><h1>Design Your Bag</h1></th>
</tr>
<tr>
<th><img src="CMBlogo.gif" style="height:100px;width:100px;" alt="logo"></th>
</tr>
<tr id="right">
<th><h2><a href="#"><span class="glyphicon glyphicon-phone-alt" aria-hidden="true"></span></a>&nbsp;&nbsp;Live Help!</h2>
<h4>(202)-629-3053</h4>
<h4><a href="mailto:brian@metrologo.com" subject="Contact and Order Information">brian@metrologo.com</a></h4></th>
</tr>
</table>
</body>
</html>

关于html - CSS 垂直对齐 :middle doesn't work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29442030/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com