[英]How to align div on the bottom inside table cell
I want the content of the second div to be bottom-aligned with the image. 我希望第二个div的内容与图像底部对齐。
<table> <tr> <td> <div> <div style="float: left;"> <img src="http://www.online-image-editor.com//styles/2014/images/example_image.png" style="max-width: 200px; max-height: 200px;"/> </div> <div style="float: right; vertical-align: bottom;"> I want this text be on the same line as the bottom of the image </div> </div> </td> </tr> </table>
You can do this with the table
and table-cell
display properties. 您可以使用table
和table-cell
显示属性执行此操作。
<table> <tr> <td> <div style="display:table"> <div style="display:table-cell"> <img src="http://www.online-image-editor.com//styles/2014/images/example_image.png" style="max-width: 200px; max-height: 200px;"/> </div> <div style="vertical-align: bottom; display: table-cell"> I want this text be on the same line as the bottom of the image </div> </div> </td> </tr> </table>
Though I'd suggest you do the styling on a separate CSS file or embedding it, rather than adding it inline. 虽然我建议您在单独的CSS文件上进行样式设置或嵌入它,而不是将其添加到内联中。 Example: 例:
.outer { display: table; } .inner { display: table-cell; vertical-align: bottom; }
<table> <tr> <td> <div class="outer"> <div> <img src="http://www.online-image-editor.com//styles/2014/images/example_image.png" style="max-width: 200px; max-height: 200px;"/> </div> <div class="inner"> I want this text be on the same line as the bottom of the image </div> </div> </td> </tr> </table>
If you want to have the text at the bottom, but also centered, you can add text-align: center
. 如果您希望文本位于底部,但也居中,则可以添加text-align: center
。
You can add display: table-cell
to div
elements inside table: 您可以将display: table-cell
添加到表格内的div
元素:
table tbody tr td div div { display: table-cell; }
<table> <tr> <td> <div> <div> <img src="http://www.online-image-editor.com//styles/2014/images/example_image.png" style="max-width: 200px; max-height: 200px;" /> </div> <div style="vertical-align: bottom;"> I want this text be on the same line as the bottom of the image </div> </div> </td> </tr> </table>
Add margin-top to your second div and it will get aligned to the right bottom of your image 将margin-top添加到第二个div,它将与图像的右下角对齐
<div style="float: right; vertical-align: bottom; margin-top:135px;">
I want this text be on the same line as the bottom of the image
</div>
Please try this one: 请试试这个:
<table> <tr> <td> <div style="display:table"> <div style="display:table-cell"> <img src="http://www.online-image-editor.com//styles/2014/images/example_image.png" style="max-width: 200px; max-height: 200px;"/> </div><br> <div style=" vertical-align: bottom;display: table-cell "> I want this text be on the same line as the bottom of the image </div> </div> </td> </tr> </table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.