CSS3 Flexbox Alignments

Currently, I am working on an e-commerce project using React/Redux. The project utilizes Flexbox for layout and design. While I have a good understanding of React, CSS3 flexbox is still new to me. Specifically, I am struggling with aligning some elements in the layout. Below you will find my React code, SCSS code, as well as both the expected and actual designs. Any assistance in achieving this layout would be greatly appreciated. Thank you in advance.

The main challenge lies in positioning the item (AED 325 above the quantity) using Flexbox.


CSS Code

.modalHeaderWrapper {
  display: flex;
  width: 100%;
  height: 50%;
  flex-direction: row;
  border-bottom: solid 1px $color-border;

   .left {
     flex: 3;
     background-color: $color-bg-primary;
   }

   .right {
     flex: 1;
     flex-direction: column;
     background-color: $gray-bg;
     border-top: 1px solid $_greyLight;
     border-right: 1px solid $_greyLight;
     border-left: 1px solid $_greyLight;

     .modalCartSummary {
       text-align: center;
       margin-top: 30px;
     }
   }
}

.aed {
  font-size: 20px;
  font-weight: lighter;
  color: $_offBlack;
}

.productBox {
  display: flex;
  flex-direction: row;
  width: 100%;

    .modalProductName {
      font-size: 14px;
      color: $_offBlack;
      text-align: left;
      line-height: 17px;
    }
}

.modalProductSummary {
  padding: 10px 20px;
}

.shippingSellerWrapperModal {
  font-size: 12px;
  margin-top: -13px !important
}

.modalImage {
  height: 74px;
  width: auto;
  margin-left: 17px;
}

React code

<div className={styles.modalHeaderWrapper}>
    <div className={styles.left}>
        <div className={styles.type}>
          <div className={styles.productAddTitle}>
              <Icon name="radio-checked" className={styles.check} />
          </div>
        </div>
        <div className={styles.productBox}>
          <div>
              <img src="{Helper.getTransformationUrl(product.image_keys[0])}" className={styles.modalImage} alt="new"/>
          </div>
          <div className={styles.modalProductSummary}>
              <div className={styles.modalProductName}>
                  {product.product_title}
              </div>
              <div className={styles.reviewbadge}>

                    <div className={styles.reviewCtr}>
                        <ProductReviewsBadge
                            reviewData={this.props.reviewsSummary}
                        />
                    </div>
              </div>
              {this.renderProductSubComponent('shippingEstimator', product, offer)}
              <div className={styles.shippingSellerWrapperModal}>

              </div>
          </div>
          <div className={styles.qntAndPriceBlock}>
              AED 325
              {I18n.getText('cart.cart-modal-qty', {qty: quantity}, 'quantity {qty}')}
          </div>
        </div>
    </div>
    <div className={styles.right}>
        <div className={styles.modalCartSummary}>
            <p className={styles.itemsNumber}>
                 'your cart has worth 
            </p>
            <span className={styles.aed}>
                AED
            </span>
            <span>
              <strong className={styles.value}>
                  {I18n.formatCurrency(this.props.cartSummary.grandTotal.value)}
              </strong>
            </span>
        </div>

        <div className={styles.btnWrapper}>
            <Button className={styles.modalBtn} onClick={() => browserHistory.push('/' + this.props.locale.locale)}>
                {I18n.getText('account.profile-address-cancel', {}, 'VIEW CART')}
            </Button>
            <Button className={styles.modalBtn} variant="transparent" onClick={this.closeModal}>
                {I18n.getText('account.profile-address-cancel', {}, 'CONTINUE SHOPPING')}
            </Button>
        </div>
    </div>
</div>

Actual Outcome

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

Expected Outcome

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

Responsive view

https://i.sstatic.net/8OR9w.png

Answer №1

You encompass the value of "AED 325" along with the quantity placeholder text and then establish a rule named qntAndPriceBlock:

.qntAndPriceBlock {
  display: flex;
  flex-direction: column;       /*  arranging the flex items vertically  */
  align-items: flex-end;        /*  aligning flex column items to the right  */
}

Below is a snippet:

.qntAndPriceBlock {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
<div class='qntAndPriceBlock'>
  <div>AED 325</div>
  <div>{I18n.getText('cart.cart-modal-qty', {qty: quantity}, 'quantity {qty}')}</div>
</div>


If the parent container .productBox functions as a flex row container, causing .qntAndPriceBlock to become a flex item, you may need to include flex-grow: 1 in order for it to take up the full width available.

.qntAndPriceBlock {
  flex-grow: 1;                 /*  occupy remaining space  */
  display: flex;
  flex-direction: column;       /*  arranging the flex items vertically  */
  align-items: flex-end;        /*  aligning flex column items to the right  */
}

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

Issue encountered when setting a background image in Angular

When trying to add a background image and set it to cover the entire browser window, I encountered an issue where the image appeared very small and did not fully cover the background. As someone new to Angular, my understanding of how this process works i ...

Creating captivating visual effects with Jquery color overlays on images

Trying to figure out how to create a hover effect on images that darkens them using Bootstrap. However, I want the effect to be contained within the white padding of the image and not cover the entire area including the white border. I've been strug ...

Creating a Context API within an Axios Request: A Step-by-Step Guide

I have successfully encrypted a JWT token in my react frontend and express backend integrated with mongodb. Now, I am facing an issue where the context state is not being updated when I try to set it using setState on the context API. The strange thing is ...

Ways to make a div fill the whole screen and allow for scrolling as well

Issue I'm facing an issue with the login.php screen and the addphoto.php screen. I want these screens to cover the entire page, but despite using the following code: .login-screen, .form-screen { position: fixed; top: 0; left: 0; disp ...

Choose links in the div and apply "motion effects."

Can anyone help me figure out why the color change for links in a div on mouseover/mouseout isn't working? Here is the HTML code: <div id="Navigation"> <a href="#">Products</a> <a href="#">Pro ...

The jQuery animate function fails to execute the specified animation (changing margin-left from -200 to +200)

I've been attempting to achieve a sliding effect for some text coming in from the left using .animate, but it's not working as expected. Styling (CSS) .body #header > a { font-family: Georgia, Courier, Verdana; font-size: 30px; p ...

The axios try-catch statement encountered an unexpected token, expecting a closing parenthesis

I encountered an unexpected issue with the error message "Unexpected token, expected ")"" when I tried adding the type any to the exception variable e in the try-catch statement. It works without any errors when I remove the any type from the cat ...

What are some ways to enhance the appearance of the initial two items in a list through CSS?

Is it possible to enhance the appearance of the first 2 elements in a list using CSS for IE8 compatibility? Here is an example of the format: <ul id="list1" style="margin-left:-20%;font-weight:bold" > <li class="xyz"> Element1 </li> ...

Implementing NextJS dynamic routing with component dynamicity

I need to develop 3 dynamic pages, each with its own unique render component. // components/AboutPage.js export default function AboutPage({ template }){ return <h1>{template}</h1> } // components/ContactPage.js export default function Conta ...

Tips for adjusting image placement in cell or xs mode using bootstrap 4

Hope you're doing well. I have a specific requirement where I need the image to be displayed to the right of the title when switching to cellular xs mode. For instance, the title should take up col-xs-9 and the image should take up col-xs-3. In the pa ...

Identifying button inputs for Xbox controllers using regular expressions

I experimented with various patterns in an attempt to detect the B button by itself, but the patterns were unsuccessful as they also detected RB and LB. I tried different variations: /B(?!^LB$|^RB$)/g /^B$|^B,$|^ B,$/g /^B$|^B,$|^ B,$(?!^LB$|^RB$)/g Th ...

The PopupControlExtender in ajaxToolkit seems to be malfunctioning when used with a textbox that has Tinymce

I recently built a website using ASP.NET, and I have a feature where a small tooltip appears on the right side of a text box when the user focuses on it. To achieve this, I am using the ajaxToolkit:PopupControlExtender in my code. <asp:TextBox ...

Tips for verifying the direct function invocation in nestjs

I have been attempting to make a direct function call and have set up the DTO, but it doesn't seem to be working. Here is the code segment where I define my DTO in the controller: @Post('/Send') async SendE(body: Send) { const mail = ...

Issue: Unhandled rejection TypeError: Unable to access properties of an undefined variable (retrieving 'data')

Currently, I am developing applications using a combination of spring boot for the backend and react for the frontend. My goal is to create a form on the client side that can be submitted to save data in the database. After filling out the form and attemp ...

Error: The variable $traceurRuntime has not been defined in the AngularJS application

Currently, I am utilizing [gulp-traceur][1] to convert es6 to js within my angularjs application (version 1.x). However, when attempting to compile a for loop, an error occurs: ReferenceError: $traceurRuntime is not defined It appears that I may need to ...

What is the proper way to integrate "require" into my Angular 2 project?

Currently, I am still in the process of trying to integrate the angular 2 code mirror module into my angular 2 application. Previously, I faced some challenges with imports which I discussed in detail here, and managed to overcome them. However, a new iss ...

JavaScript: Eliminate a specific element and retrieve the modified array

Is there a way to remove only one instance of an item from an array, even if there are multiple duplicates of that item? For example: let array = ["abc", "def", "ghi", "def"]; const toRemove = "def"; I attempted to find the index and splice the array, but ...

Tips for optimizing Slider Code to showcase an expanded selection of slides

I am currently troubleshooting a slider code on my ASP.NET website. After examining the HTML, JS, and CSS from the page theme, I noticed that only two slides are being displayed. However, when attempting to add a new slider HTML and adjusting the CSS for t ...

The jspdf tool tries to cram my extensive data into a single page, resulting in an overcrowded and barely visible PDF document

My PDF generated using Jspdf is being forced to fit in one page, making it difficult to see all the data because there is a huge amount of information present. To view the issue, please visit this link: https://jsfiddle.net/frost000/04qt7gsm/21/ var pdf ...

Alignment of inner div within the footer

I'm struggling to align my footer navigation inline with my footer title. Check out this code snippet to see what I've tried so far: https://jsfiddle.net/nkzsufov/ I experimented with using absolute and relative positioning: .footerNav { margi ...