gpt4 book ai didi

html - 使用表格和 td 在图像下方居中文本

转载 作者:太空宇宙 更新时间:2023-11-04 11:04:09 26 4
gpt4 key购买 nike

我正在制作一个网站,我正在添加一个包含图片的表格,但我无法在以下 td 单元格中将表格下方的文本居中。我当前的代码将其偏移到左侧而不是直接位于其下方。这是我的代码:

HTML:

<body>
<section>
<section id="pictures">
<div>
<img src="images/ritual4.jpg" id="slide" class="floatLeft" alt="This is a picture of a group of young men posing and smiling">
<script language="JavaScript">slideIt();</script>
<p>Ritual and Mills Music Mission</p>
<img src="images/ossian.jpg" alt="This is a picture of a group of dressed up men posing with an older gentleman.">
<p>Spaghetti Dinner Fall 2015</p>
</div>
</section>
<section id="main">
<h1>Members</h1>
<hr>
<div class="title">
<table>
<tr>
<td><img src="images/david.jpg" alt="This is a picture of David, President of the Gamma Beta Chapter."></td>
<td><img src="images/matth.jpg" alt="This is a picture of Matt Halverson, Vice-President of the Gamma Beta Chapter."></td>
<td><img src="images/zack.jpg" alt="This is a picture of Zack Bartsch, Secretary of the Gamma Beta Chapter."></td>
<td><img src="images/jacobandpete.jpg" alt="This is a picture of Jacob Walter, Tresurer of the Gamma Beta Chapter."></td>
</tr>
<tr>
<td><p id="center">XXX</p></td>
<td><p id="center">XXX</p></td>
<td><p id="center">XXX</p></td>
<td><p id="center">XXX</p></td>
</tr>

CSS:

.title{
text-align: center;
width:100%;
}
table{
margin-right: auto;
margin-left: 45px;
border-width: 1px;
}
#center{
display: table-cell;
vertical-align: center;
font-size: 12px;
margin-left: 115px;
}
td img{
display: table-cell;
vertical-align: center;
width:55%;
height:5%;
ms-transform: rotate(90deg); /* IE 9 */
webkit-transform: rotate(90deg); /* Chrome, Safari, Opera */
transform: rotate(90deg);
}

最佳答案

你的 html 有一些你需要解决的缺陷,比如设置多个同名的 id,比如 p 标签有“center”,所以我去掉了“table”部分来展示如何居中正文。

td img{
width:55%;
height:25%;
}
td, p {
text-align: center
}
    <table>
<tr>
<td><img src="images/david.jpg" alt="This is a picture of David, President of the Gamma Beta Chapter."></td>
<td><img src="images/matth.jpg" alt="This is a picture of Matt Halverson, Vice-President of the Gamma Beta Chapter."></td>
<td><img src="images/zack.jpg" alt="This is a picture of Zack Bartsch, Secretary of the Gamma Beta Chapter."></td>
<td><img src="images/jacobandpete.jpg" alt="This is a picture of Jacob Walter, Tresurer of the Gamma Beta Chapter."></td>
</tr>
<tr>
<td><p class="center">XXX</p></td>
<td><p class="center">XXX</p></td>
<td><p class="center">XXX</p></td>
<td><p class="center">XXX</p></td>
</tr>
</table>

关于html - 使用表格和 td 在图像下方居中文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34122334/

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