Placing text to the right of an image inside an <li> tag

Struggling with a simple alignment issue in my code and just don't have the time to figure it out. I have two lists, each containing images and text, but I need the text to align to the right of the images instead of wrapping underneath. Here is an example image of the problem.

<section id="providerBenefits">
  <div class="container">
    <div class="row">
      <div class="col-sm-4">
        <h1 class="display-3">Benefits<br />for providers</h1>
      </div>
      <div class="col-sm-4">
        <ul id="benefitListLeft">
          <li><img src="./assets/img/CCM-Page_12.png" />Lower costs and higher revenue</li>
          <li><img src="./assets/img/CCM-Page_16.png" />Valued-based chronic care management with full system setup</li>
          <li><img src="./assets/img/CCM-Page_23.png" />Coordination of total care plan of<br />20-minute clinical staff time</li>
        </ul>
      </div>
      <div class="col-sm-4">
        <ul id="benefitListRight">
          <li><img src="./assets/img/CCM-Page_09.png" />80-85% comprehensive care plan<br />established, implemented, and monitored</li>
          <li><img src="./assets/img/CCM-Page_18.png" />Electronic Health Record system<br />compatibility</li>
          <li><img src="./assets/img/CCM-Page_21.png" />24/7 access to statistical reports</li>
        </ul>
      </div>
    </div>
  </div>
</section>

Answer №1

Instead of using the ul li element, consider trying this method:

<div class="container">
<div class="row">
    <div class="col-md-6">
        <div class="media">
          <div class="media-left">
            <a href="#">
              <img class="media-object" src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/PjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iNjQiIGhlaWdodD0iNjQiIHZpZXdCb3g9IjAgMCA2NQ==…";>
            </a>
          </div>
          <div class="media-body">
            <h4 class="media-heading";>Media heading</h4>
            Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis.
          </div>
        </div>
    </div>
    <div class="col-md-6">
        <div class="media">
          <div class="media-left">
            <a href="#">
              <img class="media-object" src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Inl ...................................NlcmlmLCBtb25vc3BhY2U7Z ....// code continues here // ........

Answer №2

wrap img in a span and then wrap this span and text in a div with display:flex;

example: li would look like

 <li>
    <div>
        <span><img src="https://placehold.it/100x20" /></span>
        Lower costs and higher revenue
    </div>
 </li>

ul {
  list-style: none;
}

ul li div {
  display: flex;
}
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<section id="providerBenefits">
  <div class="container">
    <div class="row">
      <div class="col-sm-4">
        <h1 class="display-3">Befefits<br />for providers</h1>
      </div>
      <div class="col-sm-4">
        <ul id="benefitListLeft">
          <li><div>
          <span><img src="http://placehold.it/100x20" /></span>Lower costs and higher revenue
          </div></li>
          <li><div>
          <span><img src="http://placehold.it/100x20" /></span>Valued-based chronic care management with full system setup
          </div></li>
          <li><div>
          <span><img src="http://placehold.it/100x20" /></span>Coordination of total care plan of<br />20-minute clinical staff time
          </div></li>
        </ul>
      </div>
      <div class="col-sm-4">
        <ul id="benefitListRight">
          <li><div>
          <span><img src="http://placehold.it/100x20" /></span>80-85% comprehensive care plan<br />established, implemented, and monitored
          </div></li>
          <li><div>
          <span><img src="http://placehold.it/100x20" /></span>Electronic Health Record system<br />compatibility
          </div></li>
          <li><div>
          <span><img src="http://placehold.it/100x20" /></span>24/7 acces to statistical reports
          </div></li>
        </ul>
      </div>
    </div>
  </div>
</section>

Answer №3

Take a look at the answer provided in this example

'https://jsfiddle.net/anmolsandal/91t0sevb/'

You can achieve it using flex box. Here is the code snippet and demo

<section id="providerBenefits">
  <div class="container">
    <ul id="benefitListRight">
      <li><img src="https://dummyimage.com/100/ffffff/000000" /><span>80-85% comprehensive care plan<br />established, implemented, and monitored</span></li>
      <li><img src="https://dummyimage.com/100/ffffff/000000" /><span>80-85% comprehensive care plan<br />established, implemented, and monitored</span></li>
    </ul>
  </div>  
</section>

Css

ul
{
 padding: 0;
 margin: 0;
 list-style: none;
}
ul li {
 display: flex;
 flex-direction:row;
 justify-content: flex-start;
 align-items: center;
 margin-bottom: 20px;
}
ul li img {
 margin-right: 10px;
}

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

When an HTML string contains <br/>, the line break is not displayed

I am attempting to insert a line break between Can get report and Can order in a table cell as shown below: Can get report Can order This is the code in my csHTML file: <tbody> <tr> @{ string role = string.Empty; if (p.Can ...

Add the variable's value to the input field

It is necessary for me to concatenate a numeric value, stored in a variable, with the input fields. For example: var number = 5; var text = $("#dropdown_id").val(); I wish to append the value of the variable 'number' to 'dropdown_id' ...

Is it possible to automatically adjust the text color based on the dynamic background color?

While browsing Palantir.com, I noticed that the logo color always changes to be the inverse of the background color behind it as the background scrolls or changes. I'm currently working on a website using Wordpress and would love to achieve the same ...

JavaScript drop-down menu malfunctioning

I am currently in the process of learning web development languages, and I'm attempting to create a dropdown list using JavaScript (I previously tried in CSS without success). I would greatly appreciate it if you could review my code and let me know ...

Achieving dynamic HTML element addition through JavaScript while maintaining their record in PHP

There is an input box where the user specifies the number of new DIV elements to be added dynamically. This request is then sent to PHP via Ajax, where it prepares an HTML DIV with some inner input tags. Each DIV has a unique id attribute generated increme ...

Styling the Padding of MUI Select Component in ReactJS

Currently, I am facing an issue with the Material UI Select component where I am trying to decrease the padding within the element. The padding seems to be a property of one of the subclasses .MuiOutlinedInput-input, but my attempts to change the padding h ...

What is the best method for displaying the toggle button for Drawer/Sidebar above the main content and appbar?

After reviewing Vatsal's suggestion, it appears that moving the toggle button above the drawer is the solution to our main issue. By taking advantage of the open state of the drawer, we can adjust the left property of the button in the toggleButton cl ...

Safari doesn't seem to recognize z-index property

Currently, I am utilizing a responsive template to develop a website. An issue arises in Safari where the footer overlaps the navigation bar at the bottom of the page, despite being positioned above it earlier. It appears that the z-index attribute is not ...

Aligning divs, prevent duplicate HTML within multiple divs

Currently, I am attempting to troubleshoot a jsfiddle issue. The main problem lies in my desire for the first two divs (with class="fbox") to be aligned next to each other on the same level. Furthermore, I am looking to enable dragging the image into the ...

I am trying to center align this image, but for some reason, it's not cooperating

Attempting to center the image using margin-left: auto and margin-right: auto properties in the code snippet above has proven unsuccessful. The image is not aligning as desired. What could be causing this issue with the code? Are there any other techniq ...

The IDs and classes of HTML elements

I have two different implementations of a livechat script. On my sandbox site, the livechat is fixed to the bottom right of the page and scrolls with the window. However, on my live site (where this specific code comes from), it is attached to the footer. ...

what is the process for creating a dynamic display slide in bxslider?

I am trying to create a flexible length display using bxSlider. Here is the code I have so far. JS var duration = $('ul > li > img').data("bekleme"); $(document).ready(function () { $('.bxslider').bxSlider({ ...

How about a fading effect for the select box?

I'm currently working on creating a select tag that opens its options slowly with a fade in, fade out effect when the user clicks on "Actions." I've attempted to use jQuery for this feature but haven't had any luck. Here's my code: &l ...

Creating a CSS auto center for elements, with a unique twist

I have a design layout like this: Click here to view the image My auto-centered content is styled with the following CSS: width: 960px; margin: 0px auto; Within this auto-centered content, there is a DIV element that needs to span the full width of the ...

HTML template without the use of server-side scripting languages like PHP or Ruby on

Is there a way to develop HTML templates without relying on backend languages such as PHP or Ruby on Rails? I tried using JavaScript, but I encountered issues with my current code when adding nodes after the DOM is loaded. An ideal solution for me would ...

What are the Functions of Ctrl-K on Stack Overflow?

I'm intrigued by how to incorporate the Ctrl+K (code sample) feature for code. For example: public static void main(String args[]){ System.out.println.out("welcome"); } Is there a way to nicely format this? Do we need any specific package to ...

jQuery seems to have difficulty selecting the text of a hyperlink's element using the text() or html() methods

I have a <a href=#>Title</a> link and it's the content in between <a href="#"> attribute that I am trying to target but haven't been successful using either the text() or html() jQuery functions. The text() method is returning ...

Adding space between the cells on the far left and far right of the table and the border

I need some advice on creating a table in HTML where the borders of the leftmost and right most cells do not extend all the way to the edges of the table. Here's an example: | ____ | In this example, the top border of the cells is continuous within ...

Ways to handle errors when using navigator.clipboard.writeText

document.queryCommandSupported('copy') may not be available on all browsers. I experimented with the code below, which successfully copies the link on Firefox but fails on Opera. It displays an alert indicating that the code has been copied, yet ...

Setting the position of the center to be relative inside a table cell

I need help with centering a +/- animation within my table rows to create an accordion toggle effect for revealing more information. Despite finding a nice looking animation, I'm struggling to position it correctly within the td element in my code. He ...