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

Sass fails to import the theme for the angular material checkbox

I'm facing an issue where, despite specifying imports in my SCSS file and setting up a custom theme, the checkbox styles are not visible except for those related to typography. This is what my SCSS file looks like: @import "~bootstrap/scss/bootstrap ...

Is there a way to compel @keyframes to continue playing until it reaches its conclusion even after a mouseout event

Whenever I hover over an element, a keyframe animation starts playing. However, when I move the cursor away, the animation stops abruptly. Is there a way to ensure that it plays until the end? I've tried using the animationend event, but it doesn&apos ...

The selection button's threshold

Welcome to my website design project! I have implemented image buttons for my web page and want to restrict the number of images a user can select. If a user tries to navigate away after selecting more than 3 images, I wish to display an alert message. Her ...

Collecting, gathering content repeatedly

Hey there, just checking in. I'm currently working on extracting information related to CEO Pay Ratio and compiling links to this section for processing by a function. My goal is for the function to capture content starting from a specified tag and en ...

Styling emails with CSS: Tips for customizing fonts

I've been experimenting with setting a personalized font for an email. Within the HTML code of the email, I included the fonts using this snippet: <head> <style> /* latin-ext */ @font-face { font-family: &ap ...

Control Over Fluid Grid Layouts

Apologies for reaching out, as I usually try to figure things out on my own. However, after spending hours reading through countless pages with no success, I am at my wit's end. I'm struggling to create a 4-column 'home' landing page f ...

Having trouble with jQuery's scrollLeft function on elements that are not currently visible

Within a large container DIV that contains numerous other elements and has a scroll bar, an issue arises when determining the value of scrollLeft. When the DIV is visible, the scrollLeft() function returns the correct value, but when the element is hidden, ...

What is the significance of the space between form.validate and .ng-invalid-email.ng-dirty?

I'm currently working on an AngularJS application and I'm confused about the spacing between "form.validate" and ".ng-invalid-email.ng-dirty" in the stylesheet code below: <style> form.validate .ng-invalid-required.ng-dirty {background ...

What is preventing me from creating accurate drawings on canvas?

I'm currently working on a paint application and facing an issue. When I place the painting board on the left side of the screen, everything works fine and I can draw without any problems. However, when I move it to the right side of the screen, the m ...

Personalizing Twitter Bootstrap Directly from the Bootstrap Source Directory

As I work on developing a responsive web application using Twitter Bootstrap, my goal is to customize the Bootstrap framework to fit my specific needs. To do so, I have downloaded the Bootstrap source files from getbootstrap.com. My plan is to customize B ...

React and Mui are experiencing a peculiar issue where a background is mysteriously missing from a component in a specific location

Exploring React 16 and functional components with hooks Discussing Mui 4 framework Adding a background pattern to multiple login pages seems simple, right? Here is an example of a login page component: return ( <Box width={1} height={1}> ...

Tips for avoiding word fragmentation in <pre> code blocks

pre { white-space: pre-wrap; /* CSS 3 */ white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ white-space: -pre-wrap; /* Opera 4-6 */ white-space: -o-pre-wrap; /* Opera 7 */ word-wrap: break-word; /* Internet Explorer 5.5+ */ overflo ...

Guide to changing the border color in a Material-UI TextField component styled with an outline design

To complete the task, utilize the Material UI outlined input field (TextField component from "@material-ui/core": "^4.12.2",) and apply a custom blue color style to it. Here is the outcome of my work: Current theme override for InputL ...

Having a fixed footer in JQuery mobile does not adjust its position downwards as intended

I attempted to move the footer down using the provided code below, but it doesn't seem to be working. I even went ahead and removed all standard text from the CSS file to eliminate any potential issues. It should normally shift downward with <div ...

Tips for maintaining the active tab in Jquery even after the page is reloaded, especially for tabs that are constantly changing

$(document).ready(function(){ $('.scroll_nav li a').click(function(){ $('li a').removeClass("active_scroll"); $(this).addClass('active_scroll'); $('ul li .btn-br_all_gun').click(function(){ ...

Using JQuery to animate a division towards the left

Currently, I am in the process of developing a website that is meant to incorporate JQuery Animations. My goal is to create an animation effect for the menu items so that each item moves to the right when the mouse hovers over it. Despite my efforts to fi ...

What is causing my Javascript media query for the sidebar to not function properly?

I am working on implementing a sidebar that slides out 250px using JavaScript on the desktop view. However, I want the sidebar to take up 100% width when viewed on mobile devices. Despite my attempts to use Media Queries in JavaScript to achieve this, I am ...

Creating a PHP Class for Converting CSS3 Rules to Ensure Compatibility Across Different Browsers

Seeking assistance with developing a class that can process a style sheet, identify browser-specific CSS3 rules, and provide compatibility for all browsers. The goal is to simplify the process of writing styles for one browser and then generating CSS files ...

What is the process for ensuring that an image is set as the submit button in an HTML form on IE 7?

My HTML form is designed with an action on a PHP script, and the submit button displays a custom image instead of the default grey. While this code works perfectly in Chrome, it fails to function properly in Internet Explorer 7. Do you have any suggestions ...

jQuery's slide toggle function is limited to toggling the visibility of just one section at

Welcome to my first post! As a newbie in web development, I have just started my first project. While I feel comfortable with HTML and CSS, jQuery is proving to be a bit challenging for me. In the head section of my intranet page, I have the following cod ...