Place the small span element underneath the title span

I am currently working on a layout that includes a list item with the title "Item 0", followed by a small tag containing the text "Description Item 0", and two select menus positioned to the right. The challenge I am facing is placing the small tag below the title "Item 0" while maintaining the vertical alignment of the elements. Using a <br> tag does not work in this case since the title and the small tag are different span elements. Does anyone know a solution to ensure that the small tag appears below the title "Item 0" while still aligning the elements vertically?

For reference, you can view an example at: https://jsfiddle.net/uxvh0gmj/1/

Here is the HTML code:

<div class="container py-5">
  <div class="row no-gutters">
    <div class="col-12 col-lg-8">
      <div class="card">
        <div class="card-header">
          <h5 class="text-heading-blue mb-0 font-weight-semi-bold">Title</h5>
        </div>
        <div class="card-body">
          <ul class="list-group">
            <li class="list-group-item d-flex justify-content-between align-items-center">
              <span class="title">Item 0</span>
              <br>
              <span><small>Description Item 0</small></span>
              <form>
                <select class="custom-select form-control" style="width:100px;">
                  <option selected="">0</option>
                  <option>1</option>
                  <option>2</option>
                </select>
              </form>
              <form>
                <select class="custom-select form-control" style="width:100px;">                  <option selected="">0</option>
                  <option>1</option>
                  <option>2</option>
                </select>
              </form>
            </li>

          </ul>
        </div>
        <div class="card-footer">
          <button type="button" class="float-right btn">Next</button>
        </div>
      </div>
    </div>

And here is the relevant CSS:

.title{
  color:gray;
  font-weight:bold;
}

Answer №1

To easily create a line break, enclose the elements within the same div and maintain the br tag:

.title {
  color: gray;
  font-weight: bold;
}
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css">
<div class="container py-5">
  <div class="row no-gutters">
    <div class="col-12 col-lg-8">
      <div class="card">
        <div class="card-header">
          <h5 class="text-heading-blue mb-0 font-weight-semi-bold">Title</h5>
        </div>
        <div class="card-body">
          <ul class="list-group">
            <li class="list-group-item d-flex justify-content-between align-items-center">
              <div>
                <span class="title">Item 0</span>
                <br>
                <small>Description Item 0</small>
              </div>
              <form>
                <select class="custom-select form-control" style="width:100px;">
                  <option selected="">0</option>
                  <option>1</option>
                  <option>2</option>
                </select>
              </form>
              <form>
                <select class="custom-select form-control" style="width:100px;">                  <option selected="">0</option>
                  <option>1</option>
                  <option>2</option>
                </select>
              </form>
            </li>

          </ul>
        </div>
        <div class="card-footer">
          <button type="button" class="float-right btn">Next</button>
        </div>
      </div>
    </div>

Answer №2

DISCLAIMER: No content has been added or removed; only their positions have been swapped.

If you position the span inside another span, it will align next to it. However, if you place a <br> in between, it will be positioned below it.

Here is the revised code:

 <div class="container py-5">
  <div class="row no-gutters">
    <div class="col-12 col-lg-8">
      <div class="card">
        <div class="card-header">
          <h5 class="text-heading-blue mb-0 font-weight-semi-bold">Title</h5>
        </div>
        <div class="card-body">
          <ul class="list-group">
            <li class="list-group-item d-flex justify-content-between align-items-center">
              <span class="title">Item 0<br><span>Description Item 0</span></span>
              <form>
                <select class="custom-select form-control" style="width:100px;">
                  <option selected="">0</option>
                  <option>1</option>
                  <option>2</option>
                </select>
              </form>
              <form>
                <select class="custom-select form-control" style="width:100px;">                  <option selected="">0</option>
                  <option>1</option>
                  <option>2</option>
                </select>
              </form>
            </li>

          </ul>
        </div>
        <div class="card-footer">
          <button type="button" class="float-right btn">Next</button>
        </div>
      </div>
    </div>

The main alteration made was:

<span class="title">Item 0<br><span>Description Item 0</span></span>

You can use the following CSS code to distinguish the description span from the title:

.description {
    color: black;
    font-weight: normal;
}

Simply add class="description" to the second span.

Answer №3

Simply enclose them within the same div or span tags

.title {
  color: gray;
  font-weight: bold;
}
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css">
<div class="container py-5">
  <div class="row no-gutters">
    <div class="col-12 col-lg-8">
      <div class="card">
        <div class="card-header">
          <h5 class="text-heading-blue mb-0 font-weight-semi-bold">Title</h5>
        </div>
        <div class="card-body">
          <ul class="list-group">
            <li class="list-group-item d-flex justify-content-between align-items-center">
              <span>
                <span class="title">Item 0</span>
                <br>
                <small>Description Item 0</small>
              </span>
              <form>
                <select class="custom-select form-control" style="width:100px;">
                  <option selected="">0</option>
                  <option>1</option>
                  <option>2</option>
                </select>
              </form>
              <form>
                <select class="custom-select form-control" style="width:100px;">                  <option selected="">0</option>
                  <option>1</option>
                  <option>2</option>
                </select>
              </form>
            </li>

          </ul>
        </div>
        <div class="card-footer">
          <button type="button" class="float-right btn">Next</button>
        </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

Utilizing $.each to dynamically add data to a jQuery Mobile listview

Trying to implement a data reading mechanism using ajax resulted in unexpected html tag generation for <ul> <li>. The code snippet is as follows: (function( $, undefined ) { $(document).on("pagecreate", ".jqm-demos", function(){ ...

Move your cursor over a specific element to change the div located before it, rather than the one after

Is it possible to have <div> B affect <div> A on hover, instead of the other way around? I've only seen code for the reverse using (+) in CSS. #b:hover + #a { background: #ccc } <div id="a">Div A</div> <div id="b"> ...

Center the navbar menus at the bottom

Trying to position two menus on a webpage can be challenging. One needs to show at the center bottom, while the other should appear in the top right corner. When attempting to achieve this layout, it's important to ensure that both menus are displayed ...

Concealing a Class on the Homepage in Joomla 3

Is there a way to only hide a certain class on the home page? <div class="search-wrapper"> .search-wrapper { background: none repeat scroll 0 0 #3d4895; height: 50px; margin-top: 10px; width: 100%; } I want this class to be visible ...

The pop-up dialog on Facebook is limited to the width of the like button, cutting off any excess information

Feel free to check out my blog here. When attempting to click the "LIKE" button, the pop-up appears at the correct height, but the width is limited to the size of the button. Below is the CSS code I am using: .blog_social_media { float: right; b ...

Tips for incorporating personalized form and input directives in AngularJS while addressing issues with transcluded scope

Over the last few days, I attempted to implement something along these lines: %myform(name='somename' ng-controller='whatever') %myinput(ng-model='user.firstName' ... The controller has a user structure with firstName, l ...

A pair of buttons each displaying a unique div block

I am facing an issue with my jQuery script. I want to be able to click on one of the previewed text associated with a button and then have the other one close automatically. The desired effect is for the text to slide down using slideDown() and disappear ...

What is the best way to make a box modal function that displays a different image source than the one shown in the modal?

I'm looking to create a box modal that shows one image on the page, and then displays a different image in the popup when clicked. Here's what I currently have: <div class="row"> <div class="modal-image"><img id="myImg" src="http ...

Submitting data using various submit buttons in PHP

I am facing an issue with multiple submit buttons in my form, each containing hidden values that are dynamically generated. The problem arises when I can see the correct values in the HTML source code, but upon submitting one button, all other values get s ...

The screen is cloaked in a dark veil, rendering it completely inaccessible with no clickable

Utilizing Bootstraps modals, here is my current layout. Within the site's header, there exists a "settings" button that triggers a modal containing various options. These options are not tied to the question at hand. The button responsible for displ ...

Understanding CSS classes in ReactJS Material UI componentsJust wanted to clarify some things

When it comes to styling Material UI components, the recommended approach is to utilize their useStyles function. Here's an example: const useStyles = makeStyles(theme => ({ root: { marginTop: '15px', display: 'f ...

Loop a background image around a header that is centered in the design

I'm having an issue with creating a header with fixed dimensions and aligning it center on my webpage. I want to have small 1 px images repeat along the remaining width of the header from each edge of the main image. However, when I try to repeat the ...

Ways to retrieve an input field value without triggering form submission

I'm currently working on a payment form where users input the amount in a text field. I also have another text field on the same form that should automatically display the amount in words based on the user input. However, I'm struggling to figure ...

jQuery preventing form submission after returning false

There's a small issue that I need help with. After submitting the form and receiving a false response, it prevents resubmission. For example, if a user forgets to input their name, they will see an error message asking them to do so. However, the u ...

Here's the secret to completely getting rid of emoji as symbols

I'm facing an issue with using a regular symbol (specifically the up-right-arrow) in a Wordpress menu. When I paste the symbol character into the required field, it shows up correctly on desktop but on my iPhone, it displays as an emoji rather than th ...

An error has occurred: sendEmail function is not defined

There seems to be a simple issue here that needs my attention before diving into PHP tasks. I plan on using PHPMailer this time around. I've been attempting to learn how to submit a form on localhost for the past week, and now I'm going to try i ...

Crafting a personalized arrow for sorting headers in Angular Material

Currently working on an Angular 5 project and I'm looking to implement a custom sort icon in the header. The goal is to achieve a similar effect to this example, without using the default arrow. I attempted to modify the CSS styles, but it wasn' ...

Issue with input-group background display in bootstrap 4

My new computer is running on Windows 11 with Chrome version 97. There seems to be a bug in the original bootstrap code, as evidenced by the attachment. The issue can be seen on the Bootstrap website By adding "border-radius:0!important" to ".input-group ...

Troubleshoot: Problem with the name attribute in ASP.NET CheckBox control

When I use a checkbox with the attribute runat="server" in my ASP.NET web application, browsers encounter an issue: Uncaught Syntax error, unrecognized expression: [name=ctl00$ctl00$ContentPlaceHolder1$FormPlaceHolder$CrossFinancing] The ASP.NET code ...

The ASP Classic site is not displaying the expected styles on its elements

Currently, I am revamping an ASP Classic website. The entire site relies on a major CSS file named Main which houses all the styles used. In this file, there are not many styles as the current design is quite basic. Some elements on certain pages have thei ...