Tips for centering content using FLEXBOX

The Image photo for the containerI've been experimenting with the display:flex property in my card-container class and trying to use justify-content to center it, but the content inside the box isn't responding to the changes. Can anyone point out what I might be doing wrong? This was just a practice exercise from frontendio. Additionally, I'm facing an issue with my first button for placing an order; despite setting the padding to 0.75rem on top and bottom, and 4rem on left and right, there's still uneven spacing.

HTML

<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- displays site properly based on user's device -->

  <link rel="icon" type="image/png" sizes="32x32" href="./images/favicon-32x32.png">
  
  <title>Frontend Mentor | Order summary card</title>
  <link rel="stylesheet" href="styles.css">

  <!-- Feel free to remove these styles or customise in your own stylesheet 👍 -->
  <style>
    .attribution { font-size: 11px; text-align: center; }
    .attribution a { color: hsl(228, 45%, 44%); }
  </style>
</head>
<body>
  <section id="Card-main">
    <div class="card-container">
      <div class="top-container">
        <img src="images/illustration-hero.svg" class="main-image">
      </div>
      <div class="middle-container">
        <h1 class="title">
          Order Summary
        </h1>
        <br>
        <p class="summary">
          You can now listen to millions of songs, audiobooks, and podcasts on any device anywhere you like 

        </p>
        <div class="plan-container">

        </div>
      </div>
      <div class="bottom-container">
        <button class="btn" type="button">
          Proceed to Payment
        </button>

        <button class="btn-cancel">
          Cancel Order
        </button>

      </div>

    </div>
  </section>

</body>
</html>

CSS

@import url(https://fonts.google.com/specimen/Red+Hat+Display);
:root{
--Pale-blue: hsl(225, 100%, 94%);
--Bright-blue: hsl(245, 75%, 52%);



--Very-pale-blue: hsl(225, 100%, 98%);
--Desaturated-blue: hsl(224, 23%, 55%);
--Dark-blue: hsl(223, 47%, 23%);
}
*{
margin:0;
padding:0;
box-sizing: border-box;
}

/* Body Backgrounds */
body{
background-image:url(/images/pattern-background-desktop.svg);
background-repeat:no-repeat;
background-color:hsl(225, 100%, 94%) ;
font-family: "Red Hat Display", sans-serif;
}


/* Card Container */

.card-container{
width:33%;
height:80%;
margin: 3em auto;
background-color:hsl(225, 100%, 98%) ;
border-radius: 10%;
overflow: hidden;
display: flex;
flex-direction: column;
justify-content: center;

}
.main-image{
width: 100%;;
}
.top-container{
margin:0 0 2em 0;
}
h1.title{
font-weight: 900;
}
p{
font-size:16px;
line-height: 2em;
margin:2em auto;
color:var(--Desaturated-blue);
}
.bottom-container{
width:90%;
}
.btn{
background-color: var(--Bright-blue);
color: var(--Pale-blue);
padding:0.75rem 6rem;
border-radius: 5%;
font-size: 16px;
border:none;
font-weight: 700;
cursor:pointer;
border-radius:12px;
margin:0 auto;

}
.btn:hover{
background-color: var(--Pale-blue);
color: var(--Bright-blue);
}
.btn-cancel{
background-color: white;
color:var(--Desaturated-blue);
border:none;
cursor:pointer;
font-weight: 700;
font-size:0.9rem;
margin:2em auto;


}
.btn-cancel:hover{
color: black;
}

Answer №1

Check out this CSS snippet:

@import url(https://fonts.google.com/specimen/Red+Hat+Display);
:root{
--Pale-blue: hsl(225, 100%, 94%);
--Bright-blue: hsl(245, 75%, 52%);



--Very-pale-blue: hsl(225, 100%, 98%);
--Desaturated-blue: hsl(224, 23%, 55%);
--Dark-blue: hsl(223, 47%, 23%);
}
*{
margin:0;
padding:0;
box-sizing: border-box;
}

/* Body Backgrounds */
body{
background-image:url(/images/pattern-background-desktop.svg);
background-repeat:no-repeat;
background-color:hsl(225, 100%, 94%) ;
font-family: "Red Hat Display", sans-serif;
}


/* Card Container */

.card-container{
    width:33%;
    height:80%;
    margin: 3em auto;
    background-color:hsl(225, 100%, 98%) ;
    border-radius: 10%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;    
}
.main-image{
    width: 100%;;
}
.top-container{
    margin:0 0 2em 0;
    width: 100%;
}
h1.title{
    font-weight: 900;
}
p{
    font-size:16px;
    line-height: 2em;
    margin:2em auto;
    color:var(--Desaturated-blue);
}
.bottom-container{
    width:90%;
}
.btn{
    background-color: var(--Bright-blue);
    color: var(--Pale-blue);
    padding: 1rem;
    border-radius: 5%;
    font-size: 16px;
    border:none;
    font-weight: 700;
    cursor:pointer;
    border-radius:12px;
    margin:0 auto;
    width: 100%;
}
.btn:hover{
    background-color: var(--Pale-blue);
    color: var(--Bright-blue);
}
.btn-cancel{
    background-color: white;
    color:var(--Desaturated-blue);
    border:none;
    cursor:pointer;
    font-weight: 700;
    font-size:0.9rem;
    margin:2em auto;


}
.btn-cancel:hover{
    color: black;
}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8>;
  <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- displays site properly based on user's device -->

  <link rel="icon" type="image/png" sizes="32x32" href="./images/favicon-32x32.png">
  
  <title>Frontend Mentor | Order summary card</title>
  <link rel="stylesheet" href="styles.css">

  <!-- Feel free to remove these styles or customise in your own stylesheet 👍 -->
  <style>
    .attribution { font-size: 11px; text-align: center; }
    .attribution a { color: hsl(228, 45%, 44%); }
  </style>
</head>
<body>
  <section id="Card-main">
    <div class="card-container">
      <div class="top-container">
        <img src="images/illustration-hero.svg" class="main-image">
      </div>
      <div class="middle-container">
        <h1 class="title">
          Order Summary
        </h1>
        <br>
        <p class="summary">
          You can now listen to millions of songs ,audiobooks and podcasts on any device anywhere you like 

        </p>
        <div class="plan-container">

        </div>
      </div>
      <div class="bottom-container">
        <button class="btn" type="button">
          Proceed to Payment
        </button>

        <button class="btn-cancel">
          Cancel Order
        </button>

      </div>

    </div>
  </section>

</body>
</html>

Answer №2

Only modify a couple of CSS styles

.container{
    width:45%;
    height:75%;
    margin: 2em auto;
    background-color:hsl(225, 100%, 98%);
    border-radius: 12%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: center;

}

.wrapper{
    width:85%;
    margin: auto;
}

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

In AngularJS, how can you filter the ng-repeat value by clicking on a checkbox field?

Hey there, I'm looking to filter the ng-repeat value when a checkbox is clicked. Check out my Plunker here. By checking the checkbox labeled Role block, it should only show elements with roles value of "block". Similarly, by checking the checkbo ...

What is the best way to switch the orientation of divs from horizontal to vertical with CSS?

I currently have a footer setup with 3 divs that are displayed horizontally at the bottom of the page. <div class="footer-text footer_mainDIV"> <div class="footer_leftDIV"> All rights reserved </div> <div class="fo ...

Utilizing vanilla JavaScript or ES6 to extract data from a JSON file

I am currently working on an HTML project where I need to extract data from a JSON file that cannot be modified. I am looking to accomplish this using pure JavaScript or ES6, but I am struggling to make it work. Specifically, I am trying to retrieve a link ...

What could be the reason for my combobox failing to show any options?

I have incorporated a combobox (select) to showcase countries using Bootstrap. This is the code snippet: <select class="form-control form-control-user" id="inputCountry" name="country" placeholder="Country"> <option value="NL">Netherlands&l ...

Arranging a list using Flexbox with equal spacing between elements in each row containing three items

I'm struggling with aligning a flexbox list. I have a row of 3 elements, but when there are only 2 elements on the row, there's a gap in the middle. My goal is to have a row with 2 elements look like x x o. However, my current code displays the ...

Is there a way for me to create a button in Javascript that will mute the background music when clicked?

Currently, I am working on my website () to implement a functional mute button. The goal is for the mute button to silence the background music that is currently playing. How can I achieve this functionality when the image is clicked? Here is the HTML co ...

Error message "Undefined is not a function" occurred while using jQuery's .replace and scrollTop functions

I'm having issues with the scroll function in my code. It doesn't seem to be able to locate the ids in my HTML, even though I can't figure out why. I had a previous version that worked perfectly fine (unfortunately, I didn't save it D:) ...

What is the best way to create a slideshow that automatically starts upon loading and pauses when hovered over?

I have recently set up a div element for my slideshow. I've included a script to enable navigation using next and previous arrows. However, I am looking to add an automatic slideshow feature that stops on hover. As a beginner, I would appreciate any a ...

.display() and .conceal() functions malfunctioning

I'm in the process of creating a calendar system using the Codeigniter framework. My goal is to display a specific div every time a day cell in the calendar template is clicked. These divs are generated through a PHP for loop and populated from the d ...

CSS that adjusts to screen size for horizontal scrolling

I'm attempting to implement a horizontal scroll on a webpage so that vertical scrolling will result in horizontal movement. I came across some CSS-based code on CodePen that accomplishes this, but unfortunately it's not responsive. Is there a wa ...

When the nav menu toggler in Bootstrap 4 is clicked on a mobile screen, it causes the content to

When I view this on xs or sm screens and click on the navbar toggler, it pushes all the content, including the header where the toggler is located, down the page to accommodate the dropdown menus. This behavior seems to be different from Bootstrap 3 and Bo ...

Showing a div with seamless elegance

XHTML <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>example</title> </head> <style > body{ background: black; } ...

Adding options to a select element using JavaScript dynamically

Is there a way to create a dynamic select list for year values using JavaScript? <form action="something"> some other fields <select id="year"> </select> </form> ...

The responsive design of Bootstrap NavBar seems to be malfunctioning when viewed on an iPhone device

Having an issue in Bootstrap Studio that I can't seem to resolve. I've seen recommendations to add the following meta tag to the <head> section: meta name="viewport" content="initial-scale = 1.0,maximum-scale = 1.0", bu ...

The width of table columns is altered upon the second rendering in JQuery DataTables

Is there a way to prevent JQuery DataTables cells from extending width after adding hyperlink to cell? I am facing an issue where I have two tables on the same page. The first table column has a link which populates the second table. It works fine when th ...

Dialog overflowing due to Material-UI Dropdown

Is there a way to make the dropdown select options in a Dialog (modal) extend past the bottom border instead of getting cut off? I'm currently using MUI v5. <Dialog open={open}> <DialogContent> <Autocomplete disablePortal ...

"Extracting Text from Images: Convert Images to Text using Optical Character Recognition

While referencing a live Codepen demonstration available at this link, the application functions correctly when the "choose file" button is clicked to upload an image from the local computer and extract text from it. However, my question is how can I uploa ...

Creating a navigation bar in React using react-scroll

Is anyone able to assist me with resolving the issue I am facing similar to what was discussed in React bootstrap navbar collapse not working? The problem is that although everything seems to be functioning properly, the navbar does not collapse when cli ...

What orientation is best for the back arrow to take in a website written in Arabic?

Currently developing a website that supports Arabic language while considering security measures. The browser's back button will terminate the session, requiring users to utilize the on-page back button instead. When incorporating Arabic text, should ...

What is the method for eliminating <ol> elements that have a particular number of <

As a beginner in the world of html and css, I am reaching out for some assistance. My question is regarding how to remove the ol tags that contain 3 li elements without any class or id. Here is an example: <div class="text"> <ol> ...