The input field within the button stubbornly resists aligning with the right corner

Can anyone help me with using the class=float-right on the button labeled "Add to cart"? It seems to be not aligning properly, especially when I increase the width of the card. The "Add to cart" button is sticking to the "Description" button instead of moving to the right corner along with the input field. Any suggestions on how to correct this alignment issue?

Here's an example at jsfiddle: https://jsfiddle.net/cvrg5ep0/

<html lang="eng">
<head>
  <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css"
        rel="stylesheet" media="screen"/>
  <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
</head>

<body>
      <div class="card" style="width: 50rem; height: 28rem;"> <!-- width: 25rem -->
        <div class="view overlay">
          <img class="card-img-top" src="https://cdn.pixabay.com/photo/2018/10/05/23/24/chicken-3727097_1280.jpg"
               style="width: 25rem; height : 18rem;" alt="Card image cap">
          <div class="mask rgba-white-slight"></div>
        </div>

        <div class="card-body">
          <div class="p-2">
            <div class="float-right">
              <h3 class="card-title"><span> 5000</span> $</h3>
            </div>
            <h2 class="card-title"><span>Chicken</span></h2>

            <div class="row">

              <form th:action="@{/products/{id}(id=${product.id})}" method="get">
                <button type="submit" class="btn btn-light-blue">Description</button>
              </form>

              <div class="float-right">
                <form class="add-prod-to-cart">
                  <div class="input-group">
                    <input type="hidden" class="product-id" th:value="${product.id}">
                    <input type="number" value="1" min="1"
                           class="product-quantity form-control col-md-3">
                    <div class="input-group-append">
                      <button type="submit" class="btn btn-danger">Add to cart</button>
                    </div>
                  </div>
                </form>
              </div>

            </div>
          </div>
        </div> <!-- card-body -->
      </div> <!-- card -->
</body>

</html>

Answer №1

If you are facing issues with the code below, consider making some adjustments: The "float-right" class may not work as intended since its parent element is "row." To address this, use the flex utility class "justify-content-between" instead of the "col-md-3" class for "product-quantity." An inline style has been applied in place of the column class. Please see this link for reference: https://jsfiddle.net/c1qusLoy/

    <div class="card-body">
      <div class="p-2">
        <div class="float-right">
          <h3 class="card-title"><span> 5000</span> $</h3>
        </div>
        <h2 class="card-title"><span>Chicken</span></h2>

        <div class="row justify-content-between">

          <form th:action="@{/products/{id}(id=${product.id})}" method="get">
            <button type="submit" class="btn btn-light-blue">Description</button>
          </form>

          <div class="float-right">
            <form class="add-prod-to-cart">
              <div class="input-group">
                <input type="hidden" class="product-id" th:value="${product.id}">
                <input type="number" value="1" min="1"
                       class="product-quantity form-control" style="width: 90px">
                <div class="input-group-append">
                  <button type="submit" class="btn btn-danger">Add to cart</button>
                </div>
              </div>
            </form>
          </div>

        </div>
      </div>
    </div> <!-- card-body -->
  </div> <!-- card -->`

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

Encountering XMLHttpRequest errors when trying to make an AJAX POST request

I'm encountering an issue with a modal containing a form for submitting emails. Despite setting up the ajax post as usual, the submission is failing consistently. The console displays the following two errors: Setting XMLHttpRequest.withCredent ...

What methods can be used to prevent users from seeing the URL when submitting this form?

My form has numerous fields that I need to submit... When I submit these fields, I use the POST method to conceal the actual variables being passed to the PHP page. Unfortunately, I am unable to eliminate the complete link. Switching from GET to POST su ...

Activate a horizontal accordion when the button is clicked

I am looking to implement a dynamic horizontal accordion feature triggered by a button click. I came across this example for creating a horizontal accordion. It works well, but it is limited to only 8 accordions. I want the flexibility for users to add as ...

Ways to ensure that the height of the second row in the second column matches that of the first column

My current layout design is causing an issue where the lower green box extends beyond the total height of the entire box. I've provided a rough version of my code on codepen. Using the Bulma framework, my goal is to align the height of the left column ...

Create two floating divs that adjust their height dynamically to be equal

Situation: I have a container with two direct children, known as "left" and "right". The height of the "left" child should never exceed the height of the "right" child. However, the "right" child can extend beyond the height of the "left" child. I am stru ...

Is it possible to change the value of an HTML menu before submitting the form

I am working on a menu that displays a list of countries along with their abbreviations. Instead of sending the abbreviation value, I want to send the full name of the country as the option text. I attempted to create a function called switchval() to acc ...

Unable to use the same hexadecimal HTML entity in the value props of a React JSX component

Can someone explain why this code snippet displays dots as password and the other displays plain hexadecimal codes? <Field label="Password" value="&#x2022;&#x2022;&#x2022;&#x2022;&#x2022;" type="password" /> While this one disp ...

"The issue of the search form CSS class loading twice and causing placement issues following the completion of the AJAX

I implemented a search form that fetches data from the server and displays it in a div, which is working smoothly. However, when I added an ajaxComplete function to add a class for animating the results, it resulted in unexpected behavior. Upon entering t ...

PHP problem encountered when trying to assign values to a dropdown menu from an array

Specifically, the error message that I am encountering is: *Notice: Array to string conversion in C:\xampp\htdocs\Project1_Tables\index.php on line 38 Notice: Array to string conversion in C:\xampp\htdocs\Project1_Tables ...

Extracting text within quotation marks from HTML using Java and Selenium WebDriver

I encountered a piece of code that resembles the following: https://i.stack.imgur.com/gaX1J.png Although I am able to retrieve the link using the command System.out.print(link.getText()); it only returns the value "Saab". However, I also require the da ...

Choosing the content within a div and inserting it into an email

I have an email sender feature on my website where users can fill out input fields and hit send, resulting in me receiving an email. The text from all the input boxes is included in the email body. Additionally, there are some generated texts in divs with ...

Attempting to implement a secondary level of dropdown menu using CSS

As I begin, I want to mention that I have thoroughly reviewed all the sub sub menu questions, but unfortunately, I couldn't find anything that aligns with the code I currently have in place. Any assistance will be greatly appreciated. My current task ...

Is there a way for me to perfectly align the image and the h1 header on the webpage?

I'm facing some challenges when it comes to aligning an image and an h1 tag on the same line. I've already tried using display: inline and inline-block, but they only affect the container of the two elements. I also set the width to 100% on the s ...

When Content Div and Menu Div collide: Resolving HTML and CSS Dilemmas

I am having an issue with my content navigation div overlapping the menu navigation div. Can anyone please help me figure out what I am missing here? You can find the fiddle link below: https://jsfiddle.net/y4c2xs5j/1/ HTML: <div class="top-nav"> ...

When accessing tagName in Internet Explorer 11, the name will be returned in uppercase with the namespace included. However, in Internet Explorer 7,

My goal is to extract all child elements within a DOM element with a specific tag name and store them in an array. <xs:menu> <xs:submenu> </xs:submenu> </xs:menu> var item=menu.children.tags("XS:SUBMENU") ; Internet Explorer 7 ...

HTML5 Audio Recording Tools (including a built-in Audio Player)

While exploring Universal HTML5 players such as , I have noticed that none of them seem to include a record button. Is there any player out there that has one, similar to the image below? https://i.sstatic.net/Lpg2s.png ...

The Angular service encounters issues when interacting with REST API

Within my application, a template is utilized: <div class="skills-filter-input" ng-class="{'hidden-xs': skillsFilterHidden}"> <input type="text" ng-model="skillQuery" ng-change="filterSkills()" placeholder="Filter skills" class="filter- ...

Guide on connecting JavaScript to a Font Awesome icon

I added a fontawesome icon to my HTML as a button and now I want to use JavaScript to trigger it AJAX style <a href="#"><i id="heart" class="jam jam-heart-f"></i> Like</a> Below is the JavaScript code I attempted to use to trigger ...

Web Essentials is experiencing a problem with minified CSS

Today, while using Web Essentials 2013 for Update 3 with Visual Studio Express 2013 for Web, I encountered an issue with the minified CSS file. The website I am currently working on is built on a Twitter Bootstrap platform and utilizes two separate CSS fil ...

Turn off the automatic resizing of Internet Explorer 11 to fit the width of the viewport - IE11

Is there a way to stop Internet Explorer 11 from automatically zooming to fit the viewport width? I need the browser to respect my max-width rule and not scale the content to fill the entire width of the viewport on its own. This issue is happening in IE ...