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:

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:

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

A guide on utilizing radio buttons to delete specific rows within a table with the help of AngularJS

My current issue involves using radio buttons to delete rows in a table. The problem I'm encountering is that multiple rows are being deleted at once instead of just one. You can view an image of my table here. As we all know, with radio buttons, onl ...

The Verdana font in Microsoft Word appears with a distinct rendering when converted to an HTML-based

I'm currently working on generating a PDF from an HTML template. Our customer provided the template they previously used in Word, and they require the font to be Verdana. The challenge I'm facing is that Verdana looks smaller and has a different ...

The image slide change feature ceases to function properly when incorporating two separate functions

I have a function that successfully changes the image of a container every 5 seconds. However, I am facing an issue when trying to add 2 containers side by side and change their images simultaneously. When I run the functions for both containers, only one ...

Using .htaccess to Conceal Directories with Documents

It seems that my website is being targeted by individuals seeking to obtain all the code. I have implemented an .htaccess file that will display nothing when someone visits domain.com/images, but if they specifically request domain.com/images/logo.png, the ...

Why am I restricted to adjusting mat-elevation settings within the component's CSS exclusively?

In my Angular 8 project, I am utilizing Angular material to enhance the design of my material cards. To set up the shadow effect on these cards, I am using the elevation helper mixins provided in the documentation: https://material.angular.io/guide/elevati ...

What is the best way to add a right-hand side navigation bar without blocking the scrollbar from view?

Take a look at this webpage: I am designing a website that includes a header, a footer, and a central container with left and right navigation bars surrounding a content area. However, I want the scrollbar for the content to appear on the right side of th ...

In relation to CSS and HTML

I recently started working on a website built with HTML/CSS and encountered an issue with links highlighting when hovered over. The problem arises from the main image on the homepage containing an embedded link, causing the area under it to also highlight ...

What is the process for enabling SASS line numbers using Yeoman's Grunt.js file?

Recently, I used Yeoman (1.4.5) to scaffold a new web application. Within my Gruntfile.js, I configured it as follows: ... // When requested, compile Sass to CSS and generate necessary files sass: { options: { lineNumbers:true, sourceMap: true, ...

Leverage the power of Reactjs to add hover effects to a mapped

I am facing a challenge in styling the ListItem on hover. The issue arises when the list is dynamically generated, causing all list items to change style simultaneously when hovered over. How can I target only one element for styling? Below is the code sni ...

Accepting PHP multidimensional array through ajax

My PHP code includes a script to open a database, fetch data, and encode it into JSON format. include_once($preUrl . "openDatabase.php"); $sql = 'SELECT * FROM dish'; $query = mysqli_query($con,$sql); $nRows = mysqli_num_rows($query); if($nRow ...

Exploring the dynamic world of Angular2 animations paired with the

In my layout, I have a row with three columns and two buttons to toggle the visibility of the side panels: col-md-3 col-md-7 col-md-2 ------------------------------------ | | | | | left | middle panel | | ...

I am having trouble scrolling through the main content when the side-drawer is open. How can I fix this issue?

When the sidebar is opened, I am facing issues with the main content scroll and certain fields such as select options and search bar not functioning properly. I have included the main content in the routes from which it is being loaded. However, the scroll ...

Make sure to align images and comments seamlessly on your website just like in the comment section of YouTube

Looking for help aligning an image and two spans in one row <img src="../images/profile/profile.png" class="img" /> <span class="name">First Name</span> <span class="comment"> This is simply dumm ...

Python script utilizing Selenium is returning an empty string when trying to extract data from

When I try to retrieve the value from a dynamically loading table by clicking on the TD element, it works fine. However, when I attempt to fetch the text from the same TD element, it returns an empty string despite trying XPATH and CSS Selector methods. H ...

How can I increase the element by $100 using a dropdown selection in JavaScript?

Hey there! Looking to create a dropdown list with two shipping options: Special Shipping Normal Shipping <select> <option>Special Shipping</option> <option>Normal Shipping</option> </select> If the user selects Speci ...

What is the best way to override default CSS properties for a:hover on linked images?

I have a printer-friendly/PDF image that looks like this: Simple enough. However, when hovering over it, the background turns grey due to default hyperlink styles set as follows: #footer a:hover { color: white; background-color: #636363; -moz-transition: ...

Tips for dividing HTML code on a page into individual nodes

I am looking to extract the HTML content from a website and then parse it into nodes. I attempted the following code: function load() { $(document).ready(function () { $.get("https://example.com/index.html", function (data) { const loadpage ...

Enabling the acceptance of blank values within an HTML5 date input field

When using an HTML5 date input for a field that corresponds to a nullable datetime column in the database, how can one avoid setting an empty value in the input field? In my AngularJS application, the ng-model is connected to a scope variable with an init ...

Exploring elements using dynamic xpaths in selenium

When working with Selenium WebDriver, I am facing difficulties selecting the <input class="cs-autocomplete-input" tabindex=""> element due to its fluid ID. This is because there are multiple items with the same class name on the web page, making it c ...

Issue with combining overflow-x, Firefox, and JavaScript

In Firefox, an issue arises that does not occur in other browsers. To see the problem in action, please visit this example page: -removed- Try selecting a page other than the home page. The window will scroll to your selection. You can then scroll down u ...