Align buttons in the center of a card or container using HTML and CSS

Hi everyone, this is my first time posting so please go easy on me. I've been struggling to align the buttons at the bottom of my cards to make them look neater. I've tried using flexbox but it doesn't seem to be working. Some people have suggested using grid for vertical alignment instead. Here is my code snippet along with some images to illustrate my issue.

<main>
          <div id="main-welcome">
          <h1 id="main-title">THIS WILL BE A BIG NONE SWEAR WORD TITLE</h1>
        </div>
        <section>
          <div class="column card-style">
            <div class="card-text">
                <div id="img-container">
                <i class="fa-solid fa-user" style="color: #ff91a4;"></i>
              </div>
                <div class="title-contain">
                    <h1 id="cardTitle">About Me</h1>
                </div>
              <p class="ellipsis">Learn more about me and find links to all my socials you could ever need!</p>
            </div>
            <div class="wrap">
              <button class="button">ABOUT ME</button>
            </div>
          </div>
          <div class="column card-style">
            <div class="card-text">
              <div id="img-container">
                <i class="fa-solid fa-tree" style="color: #ff91a4;"></i>
              </div>
                <div class="title-contain">
                    <h1 id="cardTitle">Join the sub server!</h1>
                </div>
                <!--Add social icon in front of title-->
              <p class="ellipsis">
                Do you want to join a Minecraft sub server? Of course you do! Register now if it is your first time here! Or add a voucher if your subscription has run out!
              </p>
            </div>
            <div class="wrap">
              <button  class="button">REGISTER NOW</button>
              <button class="button">Add voucher</button>
            </div>
          </div>
        </section>
        </main>

CSS

 /* css cards */

  section {
    display: flex;
    flex-flow: row wrap;
    z-index: 4;
    padding-top: 12%;
    padding-left: 15%;
    padding-right: 15%;
    justify-content: center;
    flex-shrink: 0;
    flex-grow: 1;
  }

  p, a {
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: 'Open Sans', sans-serif;
    font-size: 16px;
  }
   nav > div > a {
    text-decoration: none;
    font-weight: 600;
    color: #ff91a4;
  }
  .title-contain {
    display: flex;
    justify-content: center;
    width: 100%;
    margin-bottom: -1rem;

  }
  #title-img {
    width: 2rem;
    height: 2rem;
    padding-right: 0.5rem;
  }

  #cardTitle {
    font-family: "IBM Plex Sans", sans-serif;
    font-weight: 100;
    text-transform: uppercase;
    font-size: 28px;
  }
  #img-container {
    display: flex;
    justify-content: center;
    width: 100%;
  }

  figure {
    margin: 0px;
  }

  figure img {
    width: 100%;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
  }

  figure img:hover {
    opacity: 0.6;
    transition: all .3s linear;
  }
  .column {
    box-sizing: border-box;
    flex: 1 100%;
    justify-content: space-evenly;
    margin: 20px;
    flex-shrink: 0;
    flex-grow: 1;
    z-index: 4;
  }
  .card-style {
    background-color: rgb(27, 27, 27);
    border-radius: 12px;
    border-image-slice: 1;
    box-shadow: 0px 1px 2px 0px rgba(0, 0, 0, 0.4);
    transition: all 0.25s linear;

    z-index: 4;
  }
  .card-style:hover {
    box-shadow: -1px 10px 29px 0px rgba(0, 0, 0, 0.8);
    z-index: 4;
  }

  .card-text {
    color: white;
    padding: 20px;
  }

  @media (min-width: 500px) {
    .column {
        flex: 0 0 calc(100%/2 - 40px);
    }
  }

  @media (min-width: 900px) {
      .column {
        flex: 0 0 calc(100%/4 - 40px);
    }
  }
/*Button css*/
.wrap {
  padding-top: 1rem;
  padding-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  justify-content: center;

}

.button {
  width: 140px;
  height: 45px;
  font-family: 'Roboto', sans-serif;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 2.5px;
  font-weight: 500;
  color: #000;
  background-color: white;
  border: none;
  border-radius: 45px;
  box-shadow: 0px 8px 15px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease 0s;
  cursor: pointer;
  outline: none;
  }

.button:hover {
  background-color: #ff91a4;
  box-shadow: 0px 15px 20px #cf5e71;
  color: white;
  transform: translateY(-4px);
}

the red boxes is where i would want the buttons to be all at the bottom with the same distance from the bottom

I've tried different methods such as using absolute positions or various flexbox solutions, but nothing seems to work. It either doesn't achieve the desired result or breaks the entire card layout.

Answer №1

Upon inspecting Chrome's devtool, it becomes apparent that the flex directives assigned to the card are not being utilized:

https://i.sstatic.net/Oo2qA.png

To address this issue, simply adjust the card's display property to flex and modify its direction and justification accordingly:

.column {
    box-sizing: border-box;
    flex: 1 100%;
    margin: 20px;
    flex-shrink: 0;
    flex-grow: 1;
    z-index: 4;

    display: flex; /* activate the use of flex directives */
    justify-content: space-between; /* evenly distribute space between components */
    flex-direction: column; /* arrange components from top to bottom */
}

Following these changes, the card should now appear as depicted in the following image: https://i.sstatic.net/XMpVZ.png

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

Resolving the issue of "Cannot set properties of null (setting 'innerHTML') at HTMLInputElement.loader" involves identifying the root cause and implementing

Need assistance with this code. Although I believe everything is correct, it still isn't working as expected. The error mentioned in the title comes up whenever I try to use it. I've made multiple modifications to the code but it's still not ...

The HTML was generated without any styling properties assigned

After running my script on a galaxy tab, I encountered a strange issue. I created an HTML element (div) and attempted to access the style attribute, only to receive an error message indicating that style is null. Below is the code snippet: var newDiv = d ...

In IE8, the :last-child pseudo-class appears to be ineffective

Here is the HTML structure I am working with: <div class="footerMenu"> <ul> <li>Home</li> <li>About</li> <li>Feedback</li> <li>Contact us</li> </ul> ...

How can I create a dimming effect on a webpage while a Details View Control is being displayed?

I have come across websites that use a technique where when a message box pops up, the rest of the webpage dimmed to emphasize the message. Currently, I am working on building a website using Microsoft Web Developer 2010, specifically an ASP.net site. On ...

Responsive menu not functioning properly with jQuery

I am currently working on a website located at . My goal is to incorporate the navigation plugin called MeanMenu into the site. I have followed all the instructions provided in the tutorial: adding the jQuery script to my HTML, including the CSS in the hea ...

An issue occurred while trying to establish the referrer policy

I encountered an error in my Chrome console while working on a WordPress site. The following error message showed up: "Failed to set referrer policy: The value 'http://example.com/comic/' is not one of 'always', 'default' ...

Issue with CSS style on header with hyperlink

My CSS style includes a hyperlink for the "Title" to quickly navigate back to the home page. However, when I insert a table, this hyperlink gets disabled. /* JavaScript */ .header { position: absolute; height: 85px; right: 0; top: 0; left: 0; padding: ...

An error in PHP has been detected within the CodeIgniter framework

I have encountered an error that has been frustrating me lately: An unexpected PHP Error occurred with the following details: Severity: Warning Message: strip_tags() expects parameter 1 to be string, array given Filename: inscription/loginform3.php Line ...

Hovering over the designated area will reveal the appearance of

I've encountered an issue with a list group in a card. Specifically, when hovering over the topmost item in the list group, a border appears underneath it (which should only appear when hovering). However, when I try to override this behavior using :h ...

Sliding off the canvas - concealed navigation

I have implemented CSS to hide a menu on mobile: #filter-column { position:absolute; left:-400px; } However, I want the menu to slide in from the left when the user clicks a link, and everything else should be hidden. When the layer is closed, th ...

Converting images to greyscale or transparency within a ReactJS component

I am exploring ways to transform an image into grayscale or make it transparent before using it as a background in ReactJS. Is there a way to achieve this in ReactJS? My current code snippet is shown below: <GridListTile> <img style={{ -we ...

Unable to apply color changes with jQuery

As I delve into learning jQuery, I encountered an issue while attempting to change the color of a tr element. Strangely, I was successful in updating other CSS attributes like font-style. According to my understanding so far, we use the following syntax to ...

Using a for loop, how can the property value be set in another object?

One challenge that I am facing is setting object property values. The object in question looks like this: const newPlan = { name: '', description: '', number: '', monday: { breakfast: '', ...

How can you identify the specific HTML page that a jQuery selector is targeting?

In an attempt to create jQuery code that counts the number of <img> elements on a website, I encountered a unique challenge. The website consists of 4 separate HTML pages stored in the same folder on the server. Among these pages, only "pics.html" is ...

displaying the local path when a hyperlink to a different website is clicked

fetch(www.gnewsapi.com/news/someID).then(response => newsurl.href = JSON.stringify(data.articles[0].url) fetch('https://gnews.io/api/v3/search?q=platformer&token=642h462loljk').then(function (response) { return response.json(); }).th ...

What could be causing my HTML form to only accept one response at a time?

While conducting my study, I required a Likert scale and came across a well-designed one at https://codepen.io/Buttonpresser/pen/poXVod However, I encountered an issue where selecting an answer for one question would deselect the answer for a different qu ...

Utilizing ajax for fetching a data table

I am new to using ajax and have successfully retrieved data from a table. However, I am now trying to pull in an entire data grid but not sure how to achieve this. In my index.php file, I have the following code: <html> <head><title>Aj ...

Utilize jQuery to toggle the visibility of one specific div among others with the same class

I'm currently working on a comment and like system similar to Facebook. However, I am struggling to select the specific div element! Here is a snippet of my current HTML: <div class='activoptions'><a href='#'>Like< ...

What is the parent selector in cascading style sheets (CSS

Is there a way to use pure CSS to identify the parent selector of a child element? #checkbox{ width: 24px; height: 24px; vertical-align: middle; } #checkbox:checked (parentName){ color: red; } <label for="checkbox"> <input type="check ...

Angular JS allows for the display of text from a textarea upon clicking the submit button

Q] How can I display a single text message from a textarea upon clicking the submit button in angular-js? Here is the current code that I have: <html ng-app="myApp"> <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1 ...