Text alignment in the horizontal direction does not function as expected within the `<span>` element in Bootstrap 4

The code snippet below is what I am currently working with:

   <div class="card" >
        <div class="card-block">    
            <h4 class="card-title">
                <span class="text-left">🐯</span>
                <span class="text-right">Drago</span>
            </h4>
            <span class="card-text">
                Location: ???<br>
                District: ???<br>
                Last updated: Tue, May 8th 2018
            </span><br><br>
            <div class="card-buttons" class="text-center">
                <a href="#" class="btn btn-primary btn-sm"><i class="fas fa-user-cog"></i> Edit User</a>
                <a href="#" class="btn btn-primary btn-sm"><i class="fas fa-home"></i> Manage Addresses</a>
                <a href="#" class="btn btn-danger btn-sm"><i class="fas fa-trash-alt"></i> Delete</a>
            </div>
        </div>
    </div>

The main goal is to create a Bootstrap 4 card using this structure.

My aim is to have the emoji inside the <h4> tag aligned to the left and the text following it aligned to the right. This is what I have attempted:

<h4 class="card-title">
    <span class="text-left">🐯</span>
    <span class="text-right">Drago</span>
</h4>

Unfortunately, this method is not producing the desired result, as shown in the following image: https://i.sstatic.net/vVyPd.png

I have also tried adjusting the alignment without using Bootstrap classes, by adding inline styles style="text-align: left" and style="text-align: right". However, this approach has also proved to be ineffective.

Horizontal alignment seems to work fine when using <div> elements. The issue arises only when using <span> and <div> tags with display properties set to inline-block and inline-flex.

Answer №1

To align the text to the right, you can utilize the class float-right with the .card-title element having a display:block property...

<h4 class="card-title">
        <span>🐯</span>
        <span class="float-right">Drago</span>
</h4>

If you want to align text to the right within an inline element, you can also use the text-right class.

Answer №2

.title-card {
    display: flex;
    flex-wrap: wrap;
}

.align-right {
    margin-left: auto;
}

It is recommended to assign custom classes to the title-card element instead of adjusting all title cards universally.

Check out the demo on Fiddle: https://jsfiddle.net/2xv2t12c/

Answer №3

Hope this information is useful!

Update on BS4:- New .float-{sm,md,lg,xl}-{left,right,none} classes have been introduced for responsive floats. Additionally, the redundant .pull-left and .pull-right classes have been removed in favor of .float-left and .float-right.

Make sure to use float right, and I have also included a br tag under h4 to prevent the below span from overflowing into h4.

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="card">
  <div class="card-block">
    <h4 class="card-title ">
      <span class="float-left">🐯</span>
      <span class="float-right">Drago</span>
    </h4>
    <br/>
    <span class="card-text">
                Location: ???<br>
                District: ???<br>
                Last updated: Tue, May 8th 2018
            </span><br><br>
    <div class="card-buttons" class="text-center">
      <a href="#" class="btn btn-primary btn-sm"><i class="fas fa-user-cog"></i> Edit User</a>
      <a href="#" class="btn btn-primary btn-sm"><i class="fas fa-home"></i> Manage Addresses</a>
      <a href="#" class="btn btn-danger btn-sm"><i class="fas fa-trash-alt"></i> Delete</a>
    </div>
  </div>
</div>

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

Aligning the Bootstrap 5 navbar dropdown to the right side

I'm having trouble getting a part of my navbar to align right in bootstrap 5. I've followed the new documentation, but I think I might be adding the text in the wrong place. Can someone assist me in moving my dropdown to the right side of the nav ...

Make the header background color shift as the page is scrolled down on the fixed header

I am currently using a sticky transparent header on my website www.obviagency.com Here is the CSS code: #site-header-inner { height:0px; z-index:170; margin:0 auto; width:100%; position:fixed; top:0; margin-top:10px; } I would like to change the backgr ...

Unearthing the worth of the closest button that was clicked

I am currently working on a profile management feature where I need to add students to the teacher's database. To achieve this, I am using jQuery and AJAX. However, I am encountering an issue where clicking the "add" button for each student listed on ...

How can I ensure that my jQuery code only executes after the mobile CSS has been loaded

When it comes to loading my mobile-only CSS, I typically use a media query similar to: <link rel="stylesheet" type="text/css" media="only screen and (max-device-width: 480px)" href="/includes/css/mobile.css" /> However, in addition to these CSS mod ...

What is the best way to level out the content in the article using CSS and HTML?

Can anyone help me with CSS and HTML? I have a travel blog and I want to include a related post section similar to Time.com in my articles, but I'm facing an issue. What do I need to achieve this? I want to create a section that looks like the relat ...

Tips for updating the color of buttons after they have been selected, along with a question regarding input

I need help with a code that changes the color of selected buttons on each line. Each line should have only one selected button, and I also want to add an input button using AngularJS ng-click. I am using AngularJS for summarizing the buttons at the end ...

Refresh div content dynamically with anchor tag in place

I have a dilemma with the following div that contains an anchor tag linking to a php script responsible for updating information in a database and returning to this page. My goal is to execute this php script by clicking on the anchor tag, update the datab ...

Configuring static files in Django for hosting a website in production mode

I have been attempting to serve my static files from the same production site in a different way. Here are the steps I took: First, I updated the settings.py file with the following: DEBUG = False ALLOWED_HOSTS = ['12.10.100.11', 'localhos ...

Collect data from website submissions via email

Is it possible to receive the results via email when someone submits their details on my site using a script? My server does not allow .php or .asp files, only .css. How can I achieve this? ...

applying different styles to various elements

As a newcomer to the world of jQuery, I am attempting to achieve the following goal: I have several instances of a div, and for each instance, I randomly assign a class from a predefined list in order to modify certain attributes. While this process is su ...

Could someone shed some light on why hjk fails to print whenever I click?

Why is the code not printing 'hgk' every time I click? The debounce function should run and print 'hgk' each time the button is clicked. Can someone please explain why this is not happening? const debounce=(fn,delay)=>{ ...

Accessing pseudo elements when their sibling is hovered can be achieved by using CSS selectors and combinators

I am struggling with the following html code: <div class="content"> <h2><a href="#">Hero</a></h2> <h2>Hero</h2> <div class ="tricky"></div> </div> The "co ...

The padding on this button seems to be arbitrary and nonsensical

I attempted to create a button with a red border that is positioned at the bottom and center, but the padding seems to be interfering with my design. It appears that with the border, the width extends to 100% which doesn't make sense. I have tried va ...

By default, the select option in AngularJS will have a value of either an object or null

This block of code is located in the js file: $scope.ListOption = []; $scope.ListOption.push({ Value: "0", Name: Car }); $scope.ListOption.push({ Value: "1", Name: House }); Below is the corresponding HTML code: <select class="form-control" id="Categ ...

Tips for showcasing information from an external model on your webpage without the need to reload the entire page

My goal is to dynamically show a User's name above a form field where they input their Employee # without requiring a page refresh. For instance, when they enter their # and move to the next field, I want their name to appear above based on the datab ...

Switching the horizontal tab design from Bootstrap 3 to Bootstrap 4

I'm currently working on adapting a code snippet from bootsnip that creates horizontal Bootstrap tabs with material-style design. I've encountered some challenges in converting it to Bootstrap 4, specifically in updating the CSS to use .nav-item ...

Annoying AngularJS Scrolling Problem

I am facing an issue with a Container that loads multiple views <md-content flex id="content"> <div ng-view></div> </md-content> One of the loaded views has the following structure: <div layout="column" id="selection-whit ...

Tips for displaying and hiding content in Angular2

I have a component that toggles the visibility of elements by clicking a button. This is the snippet of my HTML code: <div *ngFor="let history of histories | sortdate: '-dateModified'"> <p><b>{{ history.remarks }}</b& ...

Bootstrap modal within a nested clickable div

Utilizing the bootstrap MODAL plugin with nested divs, I have a requirement where clicking on the inside div should display the EDIT form, and clicking on the container div should show the ADD NEW form. Here is the code snippet: <div id="container" sty ...

Masonry layout organizes images in a vertical stack, with one image per row

After implementing Masonry on my website, I encountered an issue where all the images stack vertically in a single row once the page loads. Instead, I would like them to stack both horizontally and vertically. You can view the problem on My Jsfiddle. This ...