I am having trouble with the vertical alignment in the middle

I'm having trouble getting the text in front of the image to be centered within it!

Despite trying to use vertical-align middle, it doesn't seem to be working...

What could be causing this issue?

<div class="comments">
<div class="pull-left lh-fix">
<img class=foto src="/$foto" class="imgborder">
</div>

<div class="comment-text pull-left">
<span class="pull-left color strong"><a href="/anna">anna</a>:</span> dododod
</div>
</div>

.pull-left { float: left; }
.lh-fix { line-height: 0 !important; }

.comments {
  position:relative;
  display:block;
  overflow:auto;
  padding-left:15px;
  padding-top:8px;
  padding-bottom:8px;
  border:1px solid #000;
}


.comment-text {
  margin-left: 8px;
  color: #333;
  vertical-align:middle; //not working?
  line-height:normal;
  width: 85%;
  text-align:left;
}

.foto{
  width:50px;
  height:50px;
  float:left;
}

https://jsfiddle.net/a0bhv4n1/

Answer №1

When using vertical-align, it is important to note that it only works on inline elements. In this case, the class .comment-text is being applied to a div element, which is a block style element. Block style elements automatically take up all available space, making it impossible to center something within them. To overcome this, you can change the display property of .comment-text to inline-block, allowing the vertical-align property to work properly and align the content in the middle. For more detailed information, refer to MDN's article on vertical-align here.

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

What is the reason behind Bootstrap's size classes becoming ineffective after 5?

Consider this: <div class="container m-5"> is effective, while <div class="container m-9"> does not produce the desired result. It appears that any number greater than 5 does not function as expected. What could be the rea ...

Mastering the art of jQuery scrolling: A step-by-step guide

Is there a way to utilize jQuery for scrolling purposes? For example, transforming this: <ul class="nav navbar-nav navbar-right"> <li class="active"><a href="#home">Home <span class="sr-only">(current)</span></a> ...

problem arising from the box shadow and transparent areas of an image

I'm facing an issue while attempting to apply a box-shadow effect on my image. The problem arises due to certain transparent parts of the image causing unexpected results with the box-shadow. To better understand the situation, refer to the code snipp ...

Tips for aligning UI components using the style argument in a shiny application leveraging bslib 5

I recently created a shiny app ui layout that functioned perfectly with bslib 4, but upon switching to bslib 5, my formatting completely fell apart. I can't seem to figure out the reason behind this. Below is the code snippet: library(shiny) library( ...

the recurring pattern of media conditions in every single column

Hello, I'm currently involved in a project where I have implemented media conditions for my columns using Sass. Here is the code snippet: // Mobile media - 320px width @mixin mobile{ @media only screen and (max-width:767px){ width: 300px; } } B ...

Can a CSS Grid layout be achieved without prior knowledge of image sizes?

I am working on a project where I am pulling images from Reddit and aiming to showcase them in a gallery-style grid. I have tried using a flex display and resizing the images to match dimensions, but unfortunately not all images have the same dimensions ...

Position the paper-icon-button so that it is aligned to the top-right corner of the scaffold

Looking for a way to... <core-scaffold id="core_scaffold"> <core-header-panel mode="seamed" id="core_header_panel" navigation flex> <core-toolbar id="core_toolbar"></core-toolbar> <core-menu valueattr="label" ...

CSS button with folded corner illusion and dynamic transitions

I have been using the code provided below to create a folded corner effect on a button, but I am having trouble with the white background that appears in the upper left corner of the button. Is there a class I can use to make this transparent so that the y ...

Clicking to center div elements

When clicking on my div elements, they transform into flipcards and expand to a size of 600px by 600px. I want these divs to be centered in the middle of the screen when clicked, and then move back to their original position when clicked again. I've b ...

Creating floating images in AngularJS is a simple process that can add visual interest

As someone new to the world of AngularJS, I have been amazed by the stunning image animations on certain websites. I am eager to incorporate similar features into my own site. If anyone can offer guidance on how to achieve this, I would greatly appreciate ...

The carousel image slider seamlessly transitioning from the second image

I'm having an issue with the Carousel slider where it is overlapping the image from the second slide onwards. The first image loads properly, but subsequent images are not displaying correctly. Here's a reference image: https://i.sstatic.net/pyY ...

Issue with HTML CSS: There is a gap between the words "Get" and "started", causing "get" to appear on

Greetings, it appears I am encountering an issue with my website. When I refer to "Get Started," it displays as "GetStarted." However, when I insert a space between "Get" and "started," it separates onto two lines as "Get" on the first line and "started" o ...

Creating a responsive layout with organized rows and columns using Bootstrap

I'm currently facing some challenges with the arrangement of columns and rows in a bootstrap layout. I'm unsure if it's feasible to achieve what I have in mind using Bootstrap's grid system. Here is the layout I have for larger devices ...

Issue with mobile device view: BS custom dropdown toggle not functioning

Built a Bootstrap dropdown navbar with custom jQuery & CSS, but facing an issue with toggling submenu in Mobile devices. See the code snippet below: $('.dropdown').click(function() { $(this).children('.dm-lv1').toggleClass('s ...

Employing state management in React to toggle the sidebar

A working example of a sidebar that can be toggled to open/close using CSS, HTML and JavaScript is available. Link to the Example The goal is to convert this example to React by utilizing states instead of adding/removing CSS classes. To ensure the side ...

Header 1 escaping from its designated container

Encountering a problem with a h1 element not remaining within its parent div. Strangely, it remains contained until the font size of the h1 surpasses a certain threshold, causing it to spill out of the div and overlap with other content. Here is the snippe ...

In order to enhance user experience, I would like the tabs of the dropdown in the below example to be activated by

function openCity(evt, cityName) { var i, tabcontent, tablinks; tabcontent = document.getElementsByClassName("tabcontent"); for (i = 0; i < tabcontent.length; i++) { tabcontent[i].style.display = "none"; } ...

Creating a separation line between divs using HTML and customized Bootstrap styling

I'm currently practicing with bootstrap and HTML, and I would appreciate it if you could take a look at the image I've included. In the image, I have successfully created and displayed a return flight. Moving forward, my goal is to enhance its ap ...

Adaptable images - Adjusting image size for various screen dimensions

Currently, my website is built using the framework . I am looking for a solution to make images resize based on different screen sizes, such as iPhones. Can anyone suggest the simplest way to achieve this? I have done some research online but there are t ...

Stuck with the Same Theme in the AppBar of material-UI?

Currently, I am attempting to modify the theme of a material-UI AppBar by utilizing states. Strangely enough, although the icons are changing, the theme itself is not. If you'd like to take a look at the code, you can find it here: https://codesandbo ...