Aligning text and buttons in the middle of images

My goal is to align the text underneath each image and center the buttons below them. I've tried adjusting paddings and margins, but it's not solving my issue. Can someone confirm if I am correctly using the button and figcaption tags?

    figure img {
      border: 10px solid #a8eb6c;
      height: 30%;
      width: 30%;
      float: left;
      display: inline-block;
      margin: 0 16px 0 0;
    }

    figure figcaption {
      display: inline-block;
      float: left;
    }

    figcaption {
      font-size: 17px;
      margin: 30px 110px 30px 60px;
    }

    figure button {
      background-color: #a8eb6c;
      display: inline-block;
      margin: 0 110px 30px 60px;
    }
<figure>
            <img src="img/drawstring-bag.jpg" alt="drawstring-bag">
            <img src="img/charm-necklace.jpg" alt="icecream-necklace">
            <img src="img/phone-case.jpg" alt="phone-case">
              <figcaption>Purses • Tops • Skirts</figcaption>
              <figcaption>Earrings • Pendants • Clay Necklaces</figcaption>
              <figcaption>Scarves • Mittens • Plushies</figcaption>
              <button role="button">Sensational Sewing</button>
              <button role="button">Creative Charms</button>
              <button role="button">Knockout Knitting</button>
          </figure>
      </div>
    </main>

Answer №1

Your original attempt was very close, but in order to improve the structure of your code, each "card" should have its own container. To achieve this, you should include 3 figure tags, with each one containing an img, a figcaption, and a button. While using div tags would also work, utilizing figure and figcaption provides more semantic value. You can always wrap these figures inside a div container later on, based on your specific use case.

figure {
    text-align: center;
    width: 20%;
    float: left;
}

img {
    max-width: 100px;
    border: 10px solid #a8eb6c
}
<figure>
    <img src="https://www.totallypromotional.com/media/totallypromotional/images/items/TDB100/product/jpg/Polypropylene-Drawstring-Bag-TDB100-red.jpg" alt="drawstring-bag">
    <figcaption>Purses • Tops • Skirts</figcaption>
    <button role="button">Sensational Sewing</button>
</figure>
<figure>
    <img src="https://cdn11.bigcommerce.com/s-zt9cwiz411/images/stencil/1280x1280/products/2076/5316/avalon_personalized_charm_necklace__39075.1508947216.jpg?c=2&imbypass=on" alt="icecream-necklace">
    <figcaption>Earrings • Pendants • Clay Necklaces</figcaption>
    <button role="button">Creative Charms</button>
</figure>
<figure>
    <img src="https://dimg.dillards.com/is/image/DillardsZoom/zoom/kate-spade-new-york-glitter-ombre-dot-iphone-case/05482185_zi_pink_multicolor.jpg" alt="phone-case">
    <figcaption>Scarves • Mittens • Plushies</figcaption>
    <button role="button">Knockout Knitting</button>
</figure>

Answer №2

To align your content, wrap it in <div> tags and apply the text-align:center style to the div elements.

.centerContent {
  text-align: center;
  vertical-align: top;
}

figure {
  display: inline-block;
}

figure .centerContent {
  width: 28%;
  display: inline-block;
}

figure div img {
  border: 10px solid #a8eb6c;
  height: 90%;
  width: 90%;
}

figcaption {
}

figure div button {
  background-color: #a8eb6c;
}
<div class="centerContent">
  <figure>
    <div class="centerContent">
      <img src="https://www.w3schools.com/w3css/img_lights.jpg" alt="drawstring-bag">
      <figcaption>Purses • Tops • Skirts</figcaption>
      <button role="button">Sensational Sewing</button>
    </div>
    <div class="centerContent">
      <img src="https://www.w3schools.com/w3css/img_lights.jpg" alt="drawstring-bag">
      <figcaption>Earrings • Pendants • Clay Necklaces</figcaption>
      <button role="button">Creative Charms</button>
    </div>
    <div class="centerContent">
      <img src="https://www.w3schools.com/w3css/img_lights.jpg" alt="drawstring-bag">
      <figcaption>Scarves • Mittens • Plushies</figcaption>
      <button role="button">Knockout Knitting</button>
    </div>
  </figure>
</div>

Additionally, I suggest checking out Bootstrap for more helpful tools.

Hope this guidance is beneficial,

Answer №3

Thank you for checking this out! I utilized flexbox and enclosed each element within a div tag

    figure img {
      border: 10px solid #a8eb6c;
      height: 30%;
      width: 30%;
      display: inline-block;
      margin: 0 16px 0 0;
      text-align: center;
    }

    figure figcaption {
      display: inline-block;
      text-align: center;
    }

    figcaption {
      font-size: 17px;
      margin: 30px 110px 30px 60px;
    }

    figure button {
      background-color: #a8eb6c;
      display: inline-block;
      margin: 0 110px 30px 60px;
    }
    .container{
     display: flex;
     flex-direction: column;
     justify-content: center;
     align-content: center;
    }
    .center{
     text-align: center;
    }
    .main_container{
      display: flex;
      justify-content: center;
     align-content: center;
     }
<figure>
     <div class="main_container">
        <div class="container">
            <div class="center"><img src="img/drawstring-bag.jpg" alt="drawstring-bag"></div>
              <div class="center"><figcaption>Purses • Tops • Skirts</figcaption></div>
              <div class="center"><button role="button">Sensational Sewing</button></div>
        </div>
        <div class="container">
            <div class="center"><img src="img/charm-necklace.jpg" alt="icecream-necklace"></div>
              <div class="center"><figcaption>Earrings • Pendants • Clay Necklaces</figcaption></div>
              <div class="center"><button role="button">Creative Charms</button></div>
        </div>
        <div class="container">
            <div class="center"><img src="img/phone-case.jpg" alt="phone-case"></div>
              <div class="center"><figcaption>Scarves • Mittens • Plushies</figcaption></div>
              <div class="center"><button role="button">Knockout Knitting</button></div>
        </div>

      </div>
</figure>
</main>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can you please explain the meaning of this wildcard symbol?

We recently came across a part of our grunt file that was written by a former colleague. While the code functions correctly, the specific purpose of one segment remains a mystery to us! Here is the enigmatic code snippet: dist: { files: [{ ex ...

What is the best way to activate a progress bar upon clicking a button in an HTML document?

Is it possible to make a progress bar start moving upon clicking a button using only HTML? I am new to coding (just started today) and would appreciate some guidance on how to achieve this. This is what I currently have: <input type="image" src="Butto ...

Troubleshooting Bootstrap's Margin Problem

Currently, I am delving into the basics of bootstrap and encountering some challenges with using margin-auto. Specifically, I am working on positioning a navbar by using ml-auto to separate it from the brand, pushing the navbar to the right side of the p ...

The masonry plugin overlays images on top of each other

I have gone through similar questions but haven't found anything that applies to my specific case. Following an ajax call, I am adding li elements to a ul $.ajax({ url: 'do_load_gallery.php?load=all' }).done(function(result) { ...

The application of CSS styles to templates in Django is unsuccessful

The CSS theme that was previously working on the base.html is no longer functioning. I can't pinpoint what caused it to stop working. The base.html serves as the core template for all other pages. Within base.html, the following code is present: < ...

How do I view a wildcard in my ID selector using jQuery?

When I want to initially hide various content scattered around the page, I usually use the following jQuery code: $('#objective_details, #time_estimate_details, #team_members_details, #resources_details').hide(); Is there a method to utilize a ...

What is the process for specifying the content type as application/json in an Ajax request?

Do you have a smart contract named GovtContract that functions properly when utilizing curl commands? $curl -X POST -H "Content-Type: application/json" localhost:3000/govtcontract/set -d '{"value":"5"}' | jq $curl -X GET -H ...

The issue arises when attempting to reopen the jQuery UI dialog box after a div has been loaded

I am facing an issue with my survey results table where I have an EDIT button for each entry. Clicking on the EDIT button opens a dialog box with the survey results loaded from the database. After editing the answers, I want to save them in the database an ...

"Enhancing the speed of the JavaScript translate function when triggered by a scroll

I am facing an issue with setting transform: translateY(); based on the scroll event value. Essentially, when the scroll event is triggered, #moveme disappears. For a live demonstration, please check out this fiddle: https://jsfiddle.net/bo6e0wet/1/ Bel ...

Tips for saving an array of objects in local storage and transferring it from one file to another

Recently delving into the world of localstorage, I've encountered an issue while attempting to store JSON data in one file and retrieve it in another. The JSON data below was fetched from a URL, and my goal is to obtain all the feed objects in the oth ...

Utilizing multiple address parameters within a single-page application

Apologies for the lengthy post. I have encountered an issue with my code after running it through a bot that I can't seem to resolve. In my code, I aim to create functionality where you can visit the address #two, followed by two separate parameters ...

Help Needed: Adding a Simple Element to jQuery Tabs Script

I recently came across a fantastic jQuery tabs script on a website called Tutorialzine. The link to the article can be found here. As I was implementing this script, I realized I needed to customize it by adding specific classes to certain tabs. Specifica ...

What is more effective: generating/eradicating HTML components or concealing them until required?

When it comes to showing/hiding content, there are two main approaches that I would consider: Creating and destroying elements as needed using jQuery's append() and remove() methods. Having all elements already in the HTML but hiding/disabling them ...

The border-radius style will not be effective on the top part of the div

I'm currently developing a landing page for my personal use, but I've encountered an issue. There is a div with a border-radius named .popOut. The border-radius is applied to the bottom of the div but not the header part. Why is this happening? H ...

Experience a login page similar to Google's with a fully functional back button

I'm currently working on a login page that requires the user to enter their username and have it validated before proceeding. Once the username is confirmed as valid, a new input field for password entry should appear. However, I'm facing an issu ...

Struggling with implementing Vue.js for making a task list using Bootstrap 5

I'm trying to get the hang of Vue.js. I've been working on setting up a to-do list where users can input tasks, but I'm having trouble getting the list to display correctly when I define the method. It seems like my add() function isn't ...

Customizing Material-UI elements in React using CSS styling

My goal is to style all the <Chip> elements within a <Grid> that has the class .table-header, but they are not changing their style (I have a <p> that should be colored in red and it works). Why does the styling work for the <p> ele ...

The use of script src with vue.js is causing issues

I am looking to move my Vue code into an external .js file. Since I am new to Vue, I am trying to keep it simple without using webpack. However, I have encountered an issue where Vue does not work when using the script src tag in the html file. For instanc ...

Using the <object> tag in AngularJS partials for improved functionality

Trying to incorporate the <\object> tag or <\iframe> within a partial HTML file and then include that HTML in another page using ng-include. Here is my attempt: <div class="container"> <!-- This section doesn't displ ...

Unable to select checkbox within a table using Selenium WebDriver with Java

Having trouble checking a checkbox inside a table using Selenium Webdriver in Java? Even with version 2.52.0 of Selenium, the element not found error persists across different web browsers. The iFrame seems to be correct as I can interact with other compon ...