Ways to align two HTML elements on the same line but on different sides

I'm in the process of customizing this layout with Bootstrap: https://i.sstatic.net/jJlOl.png

Here's the code snippet:

<div class="container-fluid" id="products">
    <h2 class='wishlist-title text-center'>My Wishlist ({{ productList|length }} items)</h2>
    {% for product in productList %}
    <div class='userProduct text-left'>
        <a class='product-title' href="{{ product.productURL }}" target="_blank">{{ product.title|truncate(30) }}</a>
        <h4 class="current-price text-right">Current Price: ${{ product.currentPrice }}</h4>
        <h4 class="budget">Budget: ${{ product.userBudget }}</h4>
        <form class='adjust-budget' method="POST" action="{{ url_for('budget', id=product.id) }}">
            <input class='budget-update input-lg' type="number" id="new_budget" name="new_budget" min="0" max="{{ product.currentPrice }}" step=".01"><br>            
            <input class='budget-update-btn btn btn-primary' type="submit" value="Adjust Budget">
        </form>
        <form class='remove-wishlist' action="{{ url_for('delete', id=product.id) }}">
            <button class="btn btn-danger" type="submit">Remove from Wishlist</button>
        </form>
        
        {% if loop.index < productList|length %}
        <hr>
        {% endif %}
    </div>
    {% endfor %}
</div>

Here is the current CSS:

CSS code goes here...

Essentially, I want to align the current price next to the product title on the right side and remain responsive. How can I make the adjust budget button and input area appear side by side and have equal sizes? Lastly, how can I position the remove from wishlist button on the same line as the adjust budget button?

I tried using display: inline-block and adjusting width and padding, but it didn't work well responsively.

In short, I'm aiming for a design like this: https://i.sstatic.net/No2kY.jpg

Answer №1

To customize your html, follow the structure below with additional div tags to utilize the css flex property:

<div class="container-fluid" id="products">
    <h2 class='wishlist-title text-center'>My Wishlist ({{ productList|length }} items)</h2>
    {% for product in productList %}
    <div class='userProduct text-left'>
       <div class="productprice">
        <a class='product-title' href="{{ product.productURL }}" target="_blank">{{ product.title|truncate(30) }}</a>
        <h4 class="current-price text-right">Current Price: ${{ product.currentPrice }}</h4>
       </div>
       
        <h4 class="budget">Budget: ${{ product.userBudget }}</h4>
        <div class="formdiv">
            <form class='adjust-budget' method="POST" action="{{ url_for('budget', id=product.id) }}">
                <input class='budget-update input-lg' type="number" id="new_budget" name="new_budget" min="0" max="{{ product.currentPrice }}" step=".01"><br>            
                <input class='budget-update-btn btn btn-primary' type="submit" value="Adjust Budget">
            </form>
            <form class='remove-wishlist' action="{{ url_for('delete', id=product.id) }}">
                <button class="btn btn-danger" type="submit">Remove from Wishlist</button>
            </form>
        </div>
       
        {% if loop.index < productList|length %}
        <hr>
        {% endif %}
    </div>
    {% endfor %}
</div>

Additionally, include the following CSS styles:

.adjust-budget {
  display: flex;
}

.productprice,.formdiv{
    display: flex;
    justify-content: space-between;
}

This will align your layout according to your preferences. Please note that dynamic values may not be displayed as your server side code is compiled.

https://i.sstatic.net/U8LFW.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

Tips for adding an HTML code snippet to an HTML iframe with the help of jQuery

Is there a way to dynamically append an HTML code snippet to an HTML iframe using jQuery? I have stored an HTML code snippet in a MySQL Database using PHP, and I am now attempting to retrieve that snippet and add it to the iframe using jQuery. $( document ...

How to dynamically insert an em tag into a table header cell using Asp.net

In my code, I have a table with dynamically generated table headers. One of the headers is for a textbox column. var thc = new TableHeaderCell { Text = "Iteration", CssClass = "iteration" } Now, I need to modify the logic to display a label indicating wh ...

Dynamically selecting themes in an Angular application based on user input

Experimenting with an angular project where users can choose themes from a dropdown menu to modify the appearance of the application using this handy tutorial Utilizing :host-context for this purpose Encountering an issue where the selected themes are no ...

A recent addition to the webpage is causing the script to malfunction

I am experiencing an issue on my website where the radio button does not trigger the onchange event when I reload content in a DIV using (.load()). How can I solve this problem? $(window).ready(function(){ $('input[name="optionsRadios"]').on ...

Adjusting Google Maps API v3 Autocomplete dropdown width with JavaScript and SASS to match input field dimensions

I am facing an issue where the autocomplete dropdown (div with class "pac-container") is consistently 4 pixels shy of aligning perfectly with the right side of the input field. It looks like this: https://i.sstatic.net/Y0oq1.png Below is the HTML code: ...

Is there a way to adjust the background color of the clicked tab with divs and revert the others back to their original color?

<span class="row top-bar-left align-items-center" style="width: 80%; float:left"> <div tabindex="1" class="link tab" routerLink="details" routerLinkActive="active" [qu ...

CSS: Using absolute and relative positioning within a parent element can result in elements overlapping

I want to create a box in html/css where the read more hyperlink text is positioned over the background image. The goal is to have additional text added to the description without overlapping the image. Here's an example of the current issue. Curren ...

Taking a segmented snapshot of a canvas using a flexible design scheme

I am working with a canvas that contains multiple div elements representing different sections of the canvas. However, when I capture these sections, they do not appear exactly as displayed on the screen. How can I track and accurately capture the div area ...

Attempting to place the search bar within the navigation bar

Having trouble positioning a search bar in my nav bar, I'd like it to show on the right side without overlapping any other elements. Tried relative and absolute positioning with no success so far. Any assistance would be greatly appreciated, thank yo ...

Object of Razor enclosed within an anchor tag

Exploring the realm of MVC 4 and Razor is new to me. Currently, I am attempting to create a Gallery with "CSS3 Lightbox". Everything seems fine, but I am encountering difficulties with Razor and links. The issue lies in my understanding of the pre and ne ...

Arranging DIVs in a vertical layout

Currently, I am working on a design that involves organizing several <DIV> elements in a vertical manner while still maintaining responsiveness. Here are some examples: Wider layout Taller layout I have tried using floats, inline-block display, ...

changing size when hovered over with the mouse is not consistent between entering and exiting

Hi there, I'm currently utilizing the transform: scale(); property on a website and could use some assistance with a particular issue I haven't been able to find an answer for online. Here is the code snippet I'm working with: HTML: <d ...

ng-disabled directive not functioning as expected

Trying to develop a customized button directive, I aim to utilize the ng-disabled attribute and link it to a variable within the scope. Check out the HTML snippet below: <div ng-controller="MyCtrl"> <btn dis="disableBtn"></btn> </d ...

Adjust dropdown options based on cursor placement within textarea

I have a textarea and a dropdown. Whenever a user selects an option from the dropdown menu, it should be inserted into the text area. However, I am facing a bug where the selected value is being inserted at the end of the text instead of at the current cur ...

Prevent the display of arrows on number input type without the use of javascript

Is there a way to remove the up/down arrows (increment/decrement) from <input type="number"> fields in Drupal 8 without using JavaScript? A client wants to prevent accidental value changes by removing these arrows. I've attempted to create a cu ...

What is the reason for xhr.response being set to null whenever there is a warning in my PHP code?

In order to clarify, it's important to note that the .php files belong to my professor and should not be altered. The issue arises from the fact that $VALORES on line 186 is uninitialized, and I have already reported this to my professor. Below is th ...

Why does Three.js change the innerWidth and innerHeight of a div on its own after being set with the width and height of a plane?

Greetings, I have a question. In my attempt to adjust the innerWidth and innerHeight of the div container which houses a canvas element, I am using the code snippet below. The crucial part is the loader.load function that gets executed upon completion of ...

Managing web-based PDF documents with images that require authentication

Currently, I am generating PDF documents on the server side using wkhtmlpdf and nodejs. The HTML to be rendered is sent from the client side, which may contain img tags with a source. When the user previews the HTML in the browser, the images they have upl ...

Control the playback of individual HTML5 audio elements using jQuery for seamless user experience

How can I modify the code to ensure that only one HTML5 audio element plays at a time? Currently, all tracks are able to play simultaneously. I am using jQuery for play and pause functionalities. If one track is playing and another is clicked on, how can ...

Issue with custom Javascript not executing in Internet Explorer versions 9 and 10

Initially, this script is found in the document's head section. <script> document.addEventListener("DOMContentLoaded", function () { var e, t = document.querySelectorAll("div.bounceInDown"); for (var n = 0, r = t.length; n & ...