-3

I made a site here and I'm supposed to have their names under them and center them. A screenshot is here, but they aren't centred and look really weird on mobile. I need it to be responsive too. What can I add to fix this?

My 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>

My CSS:

.main {
    display: flex;
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 'center' is a deprecated element and should no longer be used. – Paulie_D Oct 07 '20 at 10:58
  • any idea on what I can do instead? – Mohammad Al nesef Oct 07 '20 at 10:59
  • @Mohammad It looks like the image itself has white space on the right-hand-side. See https://i.stack.imgur.com/jFznt.png. You'll need to crop that off, otherwise even when the image is centred you'll have white space on the right. The markup of the page doesn't match the markup posted, when I checked, but display: flex is fine, see https://css-tricks.com/snippets/css/a-guide-to-flexbox/ for some help (make ,main or parent element 100% width, height, align-items: center, justify-items: center from memory). – Anthony Oct 07 '20 at 11:12

1 Answers1

-1

Solution


Add justify-content: center; to your .main class (or the element with display: flex;). This is how you can horizontally center flex elements.

To make it responsive, add 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>

This is what it looks like on mobile:

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Fletcher Rippon
  • 1,837
  • 16
  • 21