Align text vertically next to an image

I am facing a challenge with aligning text vertically next to an image floated left. I have tried various solutions recommended on different platforms, but none seem to work for me.

Despite following the suggestions provided in this particular solution, I still encounter issues.

/* To illustrate the problem, limiting outer width */

.cart-helper-outer {
  width: 200px;
}
/* Making helper items full width */

.cart-helper-inner {
  width: 100%;
  float: left;
}
/* Aligning image to the left of the text */

.cart-helper-inner img {
  max-width: 50px;
  float: left;
  margin-right: 2.5%;
  vertical-align: middle; /* Unfortunately, this doesn't work */
}
.cart-helper-inner p {
  vertical-align: middle; /* This also proves to be ineffective */
}
<div class="cart-helper-outer">
  <div class="cart-helper-inner">
    <img src="http://placehold.it/50x50" />
    <p>Secure checkout with bank grade encryption</p>
  </div>
  <div class="cart-helper-inner">
    <img src="http://placehold.it/50x50" />
    <p>Secure checkout with bank grade encryption</p>
  </div>
  <div class="cart-helper-inner">
    <img src="http://placehold.it/50x50" />
    <p>Secure checkout with bank grade encryption</p>
  </div>
</div>

Answer №1

/* Adjusting the width to display the problem */

img{
margin:15px 0px;
}
.cart-helper-outer {
  width: 200px;
}
/* Setting helper items to full width */

.cart-helper-inner {
  width: 100%;
  float: left;
}
/* Placing image on the left side of text */

.cart-helper-inner img {
  max-width: 50px;
  float: left;
  margin-right: 2.5%;
  vertical-align: middle; /* unable to align properly */
}
.cart-helper-inner p {
  vertical-align: middle; /* alignment issue persists */
}
<div class="cart-helper-outer">
  <div class="cart-helper-inner">
    <img src="http://placehold.it/50x50" />
    <p>Secure checkout with bank grade encryption</p>
  </div>
  <div class="cart-helper-inner">
    <img src="http://placehold.it/50x50" />
    <p>Secure checkout with bank grade encryption</p>
  </div>
  <div class="cart-helper-inner">
    <img src="http://placehold.it/50x50" />
    <p>Secure checkout with bank grade encryption</p>
  </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

Why isn't the input appearing on the succeeding line below?

<label for="email2">Enter Your Email Address</label> <input type="text" name="email2" id="email2" placeholder="example: [email protected]"> <label for="phone2">Phone Number</label> <input type="text" name="phone2" id= ...

Error loading custom Javascript in MVC 4 view during the first page load

I'm working on an MVC 4 application that utilizes jQuery Mobile. I have my own .JS file where all the functionality is stored. However, when I navigate to a specific view and check the page source, I notice that all scripts files are loaded except fo ...

Discovering when the DOM has finished rendering in AngularJS with ng-repeat

I am looking for a way to trigger an alert or message upon completion of rendering in my HTML DOM using AngularJS, specifically when dealing with multiple ng-repeats. HTML Code: <body> <div ng-controller="Ctrl"> <div ng-repeat= ...

Having trouble aligning image and expanding video to fit the screen in a NextJS application

I need help with: centering the image above the waitlist sign up scaling the background video in a relative way to fill the screen regardless of browser size This is the relevant part of index.js: import Head from 'next/head' import Image from ...

How can we customize HTML images without allowing third-party JavaScript to enlarge them?

I am using Blogger to host my website and I have a basic knowledge of HTML and CSS. I want to incorporate a collaborative add-your-link feature using SimplyLinked. However... They provided me with the following HTML: <script type="text/javascript" src ...

comparing values in an array with jquery

I am attempting to retrieve the phone number and mobile number from an array using jquery. jQuery: var data = $('#PhoneLabel').text(); var array = data.split(', '); $.grep(array, function (item, index) { if (item.charAt(0) === &ap ...

Personalized validation messages with jQuery

I am currently working on a contact form using jQuery, but I am facing challenges in displaying my custom validation messages. Instead of showing the message I specified, it only displays a small popup with the generic message: "Please fill in the form". I ...

An easy method for modifying data on a webpage hosted by an ESP8266 device

In my web page, I have a form to input times. The page is saved in flash memory and I want to update the times with previously stored values in EEPROM without loading the page into RAM. I prefer not to use websockets or AJAX for this purpose. I am looking ...

Exploring the world of XML parsing with iText

I am curious to learn whether it is feasible to modify the font, color, and size while converting HTML to PDF using xmlWorker.parser. Thus far, I have successfully parsed the input as is, but now I am seeking ways to customize the font, size, color, and ...

Display upon hovering, conceal with a button located within a popup container

There seems to be an issue with the code below. Even though it works perfectly in jsfiddle, it breaks in my Chrome and other browsers right after displaying the ".popup" div. Can anyone point out what I might be doing wrong? I found similar code on this si ...

The issue with Jquery .html() function causing spaces to disappear between words

When utilizing jQuery's .html() property to populate a select box, I encountered an issue where the spaces between words were being trimmed down to just one space. Despite including multiple spaces in the option, it would always resolve to a single sp ...

Exchange information between two selected items

Below is a simplified version of the current code that I am working with: https://jsfiddle.net/2zauty83/8/ Javascript function checkboxlimit(checkgroup) { var checkgroup = checkgroup for (var i = 0; i < checkgroup.length; i++) { checkgroup[i] ...

Use CSS and JavaScript to create a visually appealing and interactive tree structure. Give the tree a dynamic design

I have been experimenting with CSS and JavaScript to create a dynamic graph based on a data table. You can view the graph that I need to replicate using CSS and JavaScript in this PDF. The example provided below showcases what I am attempting to achieve, a ...

Tips for transferring parameters using a href tag without causing a page refresh

Is there a way to pass parameter values without refreshing the page? I would appreciate any help. Thank you. searchresult.php <a href="index.php?id=<?php echo $data['ID']?>">clickme</a> index.php <?php echo $_GET['id ...

Keep track of the toggled state and prevent any flickering when the page is reloaded, all without the

After extensive searching, I couldn't find exactly what I needed. Therefore, I decided to utilize cookies to remember the toggled state of a div whether it's hidden or visible. However, I encountered an issue where there is flicker happening as t ...

Looking for a prerequisite for running this script?

Seeking assistance from a skilled Javascript expert. I specialize in template development and utilize a specific script to display my footer link in all the free templates I create. If someone attempts to remove the footer link, their site will be redirec ...

Is there a technique to block small increments in a Time Input field?

Currently in the process of developing a tool to automate task scheduling within an Angular app. I am looking for a way to restrict the user's input when selecting the hour for task execution without having to install a complex input management packag ...

Having trouble with overriding an @media query for material-ui react components?

I've been trying to modify a @media CSS rule on a Material UI component, similar to the discussions on How to over-ride an @media css for a material-ui react component and Override components like MuiTab that use media queries. However, I have not bee ...

The CSS3 :nth-child(odd) Selector is not working for either columns or rows in the selection

I am facing an issue with a table where I have used tr:nth-child(odd) to alternate row background colors. HTML /*-----------#602 SAO Styles-----------------------------*/ /*---------SAO Global------------*/ .sao-pricing-table table { border-collaps ...

Utilizing CSS to print specific columns on a separate page at regular intervals

I am facing a challenge with printing a very large HTML table, which is dynamic in the sense that the number of rows and columns can vary. When printing, the rows that exceed the page length are automatically continued on the next page. However, I also nee ...