【问题标题】:How can I make images multiple images responsive and center them? [duplicate]如何使图像多个图像响应并居中? [复制]
【发布时间】:2021-11-13 12:08:58
【问题描述】:

我在这里创建了一个网站,我应该将他们的名字放在他们的下方并居中。截图是here,但它们没有居中,在移动设备上看起来很奇怪。我也需要它来响应。我可以添加什么来解决这个问题?

我的 HTML:

<center>
    <h1>Meet our officers!</h1>
</center>
<center>
<div class="main">
    <figure>

        <center><img src="boysmeettheofficers/Baha Abed.jpg" width="150" height="150" alt="missing"></center>
        <center><figcaption>President</figcaption></center>
    </figure>
    <figure>
        <img src="boysmeettheofficers/Adnan AL-Zoibi.jpg" width="150" height="150" alt="missing">
        <figcaption>Vice President</figcaption>
    </figure>
    <figure>
        <img src="boysmeettheofficers/Omar Ibrahim.jpg" width="150" height="150" alt="missing">
        <figcaption>Secertary</figcaption>
    </figure>
    <figure>
        <img src="boysmeettheofficers/Othman Al-Mesbah.jpg" width="150" height="150" alt="missing">
        <figcaption>Historian</figcaption>
    </figure>
    <figure>
        <img src="boysmeettheofficers/Salman Al-Estath.jpg" width="150" height="150" alt="missing">
        <figcaption>Treasurer</figcaption>
    </figure>
</div>
</center>

我的 CSS:

.main {
    display: flex;
}

【问题讨论】:

  • 'center' 是一个已弃用的元素,不应再使用。
  • 知道我可以做什么吗?
  • @Mohammad 看起来图像本身在右侧有空白。见i.stack.imgur.com/jFznt.png。您需要将其裁剪掉,否则即使图像居中,右侧也会有空白区域。当我检查时,页面的标记与发布的标记不匹配,但是 display: flex 很好,请参阅css-tricks.com/snippets/css/a-guide-to-flexbox 以获得一些帮助(使主元素或父元素 100% 宽度、高度、对齐项:中心, justify-items:根据记忆居中)。

标签: javascript html css


【解决方案1】:

解决方案


justify-content: center; 添加到您的.main 类(或带有display: flex; 的元素)。这就是您可以水平居中 flex 元素的方法。

要使其具有响应性,请添加flex-wrap: wrap;

.main {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
}
<center>
    <h1>Meet our officers!</h1>
</center>
<center>
    <div class="main">
        <figure>

            <center><img src="boysmeettheofficers/Baha Abed.jpg" width="150" height="150" alt="missing"></center>
            <center><figcaption>President</figcaption></center>
        </figure>
        <figure>
            <img src="boysmeettheofficers/Adnan AL-Zoibi.jpg" width="150" height="150" alt="missing">
            <figcaption>Vice President</figcaption>
        </figure>
        <figure>
            <img src="boysmeettheofficers/Omar Ibrahim.jpg" width="150" height="150" alt="missing">
            <figcaption>Secertary</figcaption>
        </figure>
        <figure>
            <img src="boysmeettheofficers/Othman Al-Mesbah.jpg" width="150" height="150" alt="missing">
            <figcaption>Historian</figcaption>
        </figure>
        <figure>
            <img src="boysmeettheofficers/Salman Al-Estath.jpg" width="150" height="150" alt="missing">
            <figcaption>Treasurer</figcaption>
        </figure>
    </div>
</center>

这是它在移动设备上的样子:

【讨论】:

  • 感谢这个居中,但它仍然没有响应
  • @MohammadAlnesef 我更新以使其响应
  • 哦,但这在移动设备上仍然没有影响吗?我在这里上传了acaschoolgpa.000webhostapp.com/meet-our-officers-boys.html
  • @MohammadAlnesef 你没有将flex-warp: wrap; 添加到.main 类中
  • @MohammadAlnesef 你需要在手机中修复你的页脚它占用了所有屏幕我不得不将其删除才能拍照
猜你喜欢
  • 2017-05-27
  • 2014-02-23
  • 2014-07-22
  • 2018-11-07
  • 2020-08-17
  • 2017-10-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多