How to align text to the right in Bootstrap 4

I'm having an issue with my text alignment when using the original bootstrap CSS. Instead of aligning left and right, the text is simply displayed side by side.

.text-left {
    text-align: left!important
}
.text-right {
    text-align: right!important
}
<div class="cart_row">
    <span class="text-left">Price</span> 
    <span class="text-right"><?php echo int_to_format($price); ?> Ft,-</span>
</div>

Can anyone point out what I might be doing incorrectly here?

Answer №1

To utilize it, apply the flex classes that come with it.

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<div class="cart_row d-flex justify-content-between">
    <span class="text-left">Price</span> 
    <span class="text-right"><?php echo int_to_format($price); ?> Ft,-</span>
</div>

Answer №2

Span elements are considered inline.

To align content to the right, utilize the float-right class.

<div class="cart_row">
  <span>Price</span>
  <span class="float-right"><?php echo int_to_format($price); ?> Ft,-</span>
</div> 

To see this code in action, visit: https://codepen.io/manaskhandelwal1/pen/GRJrebW

Answer №3

To grasp the concept of css-bootstrap, focus on understanding the Grid System with rows and width.

Use the .pull-left class to float an element to the left and the .pull-right class to float it to the right.

Start by creating a row with a specified width, then divide it into 2 inner sections with separate widths.

For more information, refer to: Quick floats

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>

<!DOCTYPE html> 
<html> 

<head> 

<!-- Include Bootstrap CSS -->
<link rel="stylesheet"
href= 
"https://stackpath.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"> 
</head> 

<body> 
<div class="row col-md-12">
 <div class="col-md-3">
    <span class="pull-left bg-success">left test1</span> 
    <span class="pull-right bg-warning">right test1</span>
 </div> 
 <div class="col-md-3">
    <span class="pull-left bg-info">left test2</span> 
    <span class="pull-right bg-danger">right test3</span>
 </div>
 
</div>
</body> 

</html>

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

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 ...

What is the most efficient way to organize an array by date?

Here is the data I have: const data = [{date: "2022-05-10 13:36:00", open: 155.535, low: 155.4, high: 155.67, close: 155.44}, {date: "2022-05-10 13:35:00", open: 155.23, low: 155.2102, high: 155.62, close: 155.53}, {date: "2022-05 ...

Is there a way to stop objects in a particular list from being dragged into another nested ul using jquery sortable?

I am faced with a challenge regarding nested lists, specifically when it comes to preventing parent-parent list items from dropping into an inner <div> within an <li> <div> that already contains its own <ul> <li> list. Additio ...

When attempting to retrieve the value of my select element, I encounter difficulty due to a hidden field that only becomes visible when a certain option is selected

I have a dropdown menu with different options, including one labeled "other". When the user selects "other", a hidden text field appears for them to enter a custom value. This functionality works correctly. However, if the user selects any other option and ...

Design buttons that are generated dynamically to match the style

I have a challenge in styling dynamically generated buttons. I've developed a component responsible for generating these dynamic buttons. const TIMER_PRESETS: Record<string, number> = { FIFTHTEENSEC: 15, THIRTYSEC: 30, FORTYFIVESEC: 45, ...

Invoking partial view via Ajax

I am using Ajax to call a partial view, but it is returning as undefined. This is my controller code: [HttpGet] public ActionResult CallPartial() { if (Request.IsAjaxRequest()) { return PartialView("~/Views/Partial1"); ...

What steps should be taken to ensure that text starts after an image concludes, rather than displaying on top

I am facing an issue with my website layout. I have set an image as the background and a navigation bar that displays over the image. However, when I add a p tag, it also displays over the image instead of below it. I have used position absolute to keep th ...

Effortless Numerical Calculation for Trio Input Fields

I am in the process of setting up three numeric input fields that will automatically calculate and display results on the side. I am struggling with this task as I am not familiar with using ajax. Can someone assist me in implementing this functionality us ...

What are some methods to avoid clipping absolute positioned elements while maintaining a box shadow around the parent div?

Here is an example to illustrate my question: Example Code The code provided above is a simplified version of my actual code. I am facing an issue where setting the wrap-div to overflow: visible prevents the menu from being cut off, but it also causes the ...

Learn how to efficiently execute a function multiple times using pure JavaScript

I am trying to create a tabbed content functionality with multiple elements. How can I utilize the same function for various elements declared in a variable? For example, I want to clone the parent div.tabs element with similar content but different ids an ...

"JavaScript that doesn't rely on a specific browser

Why does this code behave differently across browsers? What modifications are needed to ensure consistent behavior in all of them? In Firefox, it functions correctly, using the URL /some/path/?searchedText=sometext. However, in IE, nothing happens when cli ...

Utilizing React to transform object data into table columns

I need assistance mapping the following object array into table columns using react. The table has 4 columns, and I want these values to be displayed in them. There are also two rows that need to be filled out. <table> <tbody> ...

What is the best way to set values for DT checkboxes?

Is it feasible to set a value of TRUE/FALSE to an input type checkbox through JavaScript in a shiny app? Consider the scenario where there is a reactive data table: data:vals<-reactiveValues() vals$Data<-data.table( Brands=paste0("Brand&qu ...

JS Issue with Generating Content

Introduction( kind of :) ) Starting with the process of generating 5 coffee beans for each cup of coffee. The coffee class includes a strength attribute, and my goal is to visually distinguish the coffee beans which have a strength greater than the select ...

What is the process of dynamically altering the content inside a td element?

Is there a way to dynamically change the content of a td based on the state of a checkbox? If the checkbox is unchecked, the td should remain plain, but if checked, I want the text to have a specific style: b style="font-family:Tahoma;font-size:8pt;color: ...

The HTML code does not display list items

I'm having trouble getting the image to display in the list element of my toolbar creation. Here is my CSS and HTML code: ...

Is it possible to handle parsing of partial xml text within JavaScript using the newest version of Firefox?

After reviewing the responses, it appears that DOMParser may struggle with handling incomplete and not well-formed XML data. Considering most major browsers can manage faulty HTML source code, I am curious if there is a workaround to have the browser inte ...

Incorporating Content Dynamically with JavaScript AJAX Functions

I've recently developed a webpage that utilizes an AJAX call to populate a specific div with the following content: <div class="latest-jobs"> <ul class="list-of-jobs"> <li> < ...

Display outcome generated by JavaScript in the input box

I've successfully implemented a date/time picker in a form. Using JavaScript, I've created a script to calculate the difference between two date fields and display it in a third field labeled Course Duration. However, I'm encountering an i ...

"Access denied: Resteasy and ajax do not support this method (error

Encountering a login problem, although registration is functioning smoothly. Tech stack - HTML/AJAX/JQuery->Resteasy (Wildfly 10.1.0 Final) The URL - https://www.test.com/login.html - (actual URL name altered) Upon submitting the form with method type ...