Having trouble aligning elements in Bootstrap inline

I am trying to get certain elements to display in a single line. Here is the HTML code I have:

h2 {
  color: Red;
  font-size: 30px;
  font-weight: bold;
  display: inline-block;
}

img {
  display: inline-block;
}

h2.class1 {
  color: green;
  font-size: 20px;
  display: inline-block;
}

h2.class2 {
  color: yellow;
  font-size: 14px;
  display: inline-block;
}

.bg {
  background-color: black;
}
<!-- Bootstrap -->
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="abc9c4c4dfd8dfd9cadbeb9e859b859b86c9cedfca98">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet">

</html>

<!-- Code -->
<div class="bg">
  <div class="container-sm center" style="margin-top: 25px;">
    <div class="d-grid gap-2 col-6 mx-auto">
      <img src="https://via.placeholder.com/50" width="50px" height="50px" style="border-radius:25px;">
      <h2 style="font-size: 25px;">Some Heading Text</h2>
      <h2 class="class1">{}></h2>
      <h2 class="class2"> Some Tagline Like Text</h2>
      <hr>
    </div>
  </div>
</div>

This is the output I got: https://i.sstatic.net/QWgFb.png.

And this is how I would like it to look (after removing bootstrap): https://i.sstatic.net/UmOeK.png

Edit: Methods I have tried:-

  • d-inline-block
  • inline-block
  • float property
  • adjusting margins
  • Using some Bootstrap classes (although I forgot which ones)
  • Code snippets sourced from stackoverflow

Answer №1

Check out the updated code below with significant modifications to your markup and CSS styles

<!DOCTYPE html>
<html>
  <head>
    <link
      href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="02606d6d76717670637242372c322c322f6067766331">[email protected]</a>/dist/css/bootstrap.min.css"
      rel="stylesheet"
    />
    <style>
      *{
        margin: 0;
        padding: 0;
      }
      h2 {
        color: Red;
        font-size: 30px;
        font-weight: bold;
        
      }

     
      h2.class1 {
        color: green;
        font-size: 20px;
        
      }

      h2.class2 {
        color: yellow;
        font-size: 14px;
        
      }

      .bg {
        background-color: black;
      }
    </style>
  </head>

  <body>
    <div class="d-flex flex-row justify-content-start bg-dark">
      <img
        src="https://via.placeholder.com/50"
        width="50px"
        height="50px"
        style="border-radius: 25px"
      />
      <div class="d-flex align-items-baseline my-4">
        <h2 style="font-size: 25px">Some Heading Text</h2>
        <h2 class="class1">{}></h2>
        <h2 class="class2">Some Tagline Like Text</h2>
      </div>
    </div>
  
  </body>
</html>

Answer №2

replace d-grid with d-inline-flex

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<!-- Bootstrap -->
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b8dad7d7cccbcccad9c8f88d9688968895daddccd98b">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>



</html>

<!-- Code -->
<div class="bg">
  <div class="container-sm center" style="margin-top: 25px;">
    <div class="d-inline-flex col-12 ">
      <img  src="https://via.placeholder.com/50" width="50px" height="50px" style="border-radius:25px;">
      <h2  style="font-size: 25px;">Some Heading Text</h2>
      <h2 class="class1">{}></h2>
      <h2 class="class2"> Some Tagline Like Text</h2>
      <hr>
    </div>
  </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

Is there a way to automatically close the dropdown when a button is clicked?

A Bootstrap 5 dropdown menu is displayed below, consisting of labeled checkboxes and equipped with data-bs-auto-close="outside" attribute to auto-close the menu on outside click. <div class="dropdown"> <button type="button" c ...

How can I show a "buffering" message in jPlayer?

I need assistance with jPlayer. Here is the code I am using: $("#jquery_jplayer_1").jPlayer({ ready: function () { $(this).jPlayer("setMedia", { title: "Alin", artist: "song", mp3: "utl" ...

Is there a way to process the output of phantom.js in PHP efficiently?

I have successfully retrieved output from a phantom.js request via the command line and it meets my expectations. Now, I am interested in invoking phantom.js from a php script and then analyzing the output for specific content. My phantom.js script appear ...

Creating multiple lines with kineticjs in a HTML5 environment can be a

Referencing the following page: KineticJS - Drawing Lines with Mouse KineticJs is effective in creating lines, shapes, and enabling drag-and-drop functionality. The provided example consistently redraws the same line, prompting the question of how to draw ...

Having trouble making jQuery code disable input field based on checkbox status

Is there a way to automatically disable the price input field once the checkbox is checked and clear any existing text? I seem to be having trouble with my current code.. <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <scr ...

Safari not updating Angular ng-style properly

I created a simple carousel using Angular and CSS animations which works well in Chrome. However, I recently tested it in Safari and noticed that the click and drag functionality does not work. I've been trying to fix this issue for days and could use ...

The function element.checked = true/false in Vanilla Javascript seems to be malfunctioning

Here is the HTML code I am working with: <ul class="nav md-pills pills-default flex-column" role="tablist"> <li class="nav-item"> <input type="radio" name="q01" value="1" hidden checked> <a class="nav-link choice01 ...

Creating intricate HTML components using jQuery/Javascript

My current challenge involves receiving data from JSON and dynamically displaying it on a web page within complex HTML structures, such as tables with lists. Every time new JSON data is received, I need my HTML elements to be dynamically regenerated. For ...

Issues arise when setting a delay for CSS transitions to occur due to the

I'm trying to create a scroll bar that only appears when hovered over, similar to how it works on Facebook where the scroll bar shows up slowly instead of all at once. I've tried using CSS transition delay, but it doesn't seem to be working ...

"Vertical Line Encoding: A Strategy for Improved Data

Can someone help me with a coding issue I'm facing on my website? I am trying to create three vertical lines to separate images in columns, but every time I exit the editor and preview the site, the position of the lines changes. I'm new to HTML ...

What is the best way to ensure that all components are updated simultaneously?

I am facing an issue with showcasing relative time using momentjs - it displays 'a few seconds ago', '5 minutes ago', 'an hour ago', etc... upon rendering the HTML. However, the problem is that it remains stuck in that initial ...

Ensure the date is displayed in the format of dd-mm-yyyy when using the input type=date

Here is the code I am currently using : <input type="date" class="form-control" id="training_date" name="training_date" placeholder=" select" value="" onfocus="(this.type='date')" onfocusout="(this.type='date')" max=<?php echo ...

Issue with hiding div using jQuery's length option

I'm currently using Drupal 7.0 along with the Galleria Javascript Image Gallery in fullscreen theme. My theme includes two navigation buttons, and here is the CSS code for them: .galleria-image-nav { height: 159px; opacity: 0.8; position: fixed ...

Unable to remove the vertical dropdown menu padding issue in Firefox

issue: https://i.stack.imgur.com/qisVn.jpg My website appears correctly on IE, Opera, and Chrome, but in Firefox, there is a spacing problem between each image in the dropdown menu. I suspect the issue lies within the CSS code. The same spacing issue occ ...

Creating a JavaScript anchor through a backend bean function

Is it crazy to want to create an anchor that can be called from a backing bean method using JavaScript? I need to do this for specific reasons, utilizing a commandButton with ajax set to false. I'm attempting the following approach: RequestContext.g ...

Function call fails when parameters are passed

I've been grappling with this conundrum for a few weeks now, on and off. Perhaps someone else will spot the glaringly obvious thing that I seem to be overlooking. At the present moment, my primary goal is to simply confirm that the function is operat ...

Icon dropdown in Bootstrap

Looking for a solution to modify this dropdown using only bootstrap classes. Instead of the current text "Dropleft" and left arrow icon, how can I replace it with an icon fas fa-ellipsis-h? <button type="button" class="btn btn-secondary ...

What is the best way to conceal a title while still displaying the content with the use of *ngIf in Angular

Is there a way to hide the title "Title.PhoneInfo" without hiding the content? When I set the "IsTitleDisabled" property to true, both the title and content are hidden. I only want to hide the title. Is there a solution to achieve this? <form-layout-c ...

Prevent the Spread of an Event for a Particular Controller

tl;dr Summary Develop a function that is able to handle a specific event on multiple elements within a hierarchy. The function should execute when the event is triggered on the first element reached during bubbling, but should not continue executing or re ...

The system encountered a TypeError: Unable to access the 'nativeElement' property as it is undefined

Hello, I am a beginner in Angular 2 and currently working on an image cropping plugin. My goal is to display the image on a canvas element. Below is my HTML code: <div class="row"> <div class="col-sm-6"> <canvas id="layout" width="40 ...