html - 对齐图像下的文本

标签 html css

我的 HTML 页面中有 2 个图像作为链接,我想在 <a> 中的每个图像下插入文本。标签是可点击的,所以我尝试了这段代码:

<div align="center" style="margin-top: 150px;">

    <a href="shortcode.php" style="padding-right: 50px;">
    <img src="img\logo_sh.gif" width="300" height="300"/>
    <p> Some text </p></a>

    <a href="workorder.php" style="padding-left: 50px;">
    <img src="img\logo_wo.gif" width="300" height="300"/>
    <p> another text </p></a>

</div>

但我遇到了这样的样式问题 Image我希望他们像这样位于中心 Image

最佳答案

尝试将此 CSS 添加到您的容器中:

#img_container {
  display: flex;
  flex-direction: row;
}

I highly recommend you to read this guide about Flexbox. It will help you to understand Flexbox and it will avoid several headaches while centering DOM elements.

这是一个工作片段。

#img_container {
    display: flex;
    flex-direction: row;
}
<div align="center" id="img_container" style="margin-top: 150px;">

    <a href="shortcode.php" style="padding-right: 50px;">
    <img src="img\logo_sh.gif" width="300" height="300"  id="shortcode_icon" />
    <p> Some text </p></a>

    <a href="workorder.php" style="padding-left: 50px;">
    <img src="img\logo_wo.gif" width="300" height="300"  id="workorder_icon" />
    <p> another text </p></a>

</div>

编辑:您也可以将其添加为内联样式。

<div align="center" id="img_container" style="margin-top: 150px; display: flex; flex-direction: row;">

关于html - 对齐图像下的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49881396/

相关文章:

javascript - 检测是否启用了 chrome 面板

php - WordPress 站点上的 FTP 图像显示问题

html - 使用 SASS 变量生成内联 CSS

html - 如何设置div的宽度以适合内容?

html - firefox 菜单的不同行为

javascript - 使用 jQuery.load 加载后如何使用 MathJax 格式化 html?

javascript - 单击它移动窗口的元素中心

css - 为什么 'overflow: auto' 清除 float ?为什么需要透明的浮子?

javascript - 如何在 HTML CSS 网络应用程序中使用通用的页眉和页脚?

javascript - dragleave 冒泡事件的问题