Ways to center text vertically alongside an image

<ion-view view-title="个人信息">
<ion-content>
    <style>
        .user-details {
            display: flex;
            align-items: center;
            justify-content: space-between;
            height: 80px;
        }
        .user-detail-left {
            border: 1px dashed red;
        }
        .user-detail-avatar {
            width: 64px;
            height: 64px;
        }
    </style>
    <div class="list">
        <a class="item user-details" href="#">
            <span class="user-detail-left">头像</span>
            <img class="user-detail-avatar" src="img/wechat.png"></img>
        </a>
        <a class="item" href="#">
            <span>昵称</span>
            <span>xxx</span>
        </a>
        <a class="item" href="#">
            <span>帐号</span>
            <span>xxx</span>
        </a>
    </div>
</ion-content>

https://i.sstatic.net/n2tWB.png

My code looks like this, no matter what I do, it still aligns to the top. My question is how do I make the text align in the middle.

So, I want the text and image to be aligned vertically centered, with the text on the left and the image on the right.

Answer №1

Consider utilizing the line-height technique if you are confident that the text will all be on one line. There are primarily two options to consider - adjusting the line-height or using padding-top. While padding can impact the dimensions of the element, line-height should not have the same effect. However, it is most effective when dealing with single-line text or titles.

I am uncertain about whether vertical alignment will function correctly for an inline text element.

Answer №2

Here is a code recommendation for you:

style="vertical-align:middle"

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

Rotating and moving two boxes using CSS3 transformations

I have two boxes, each measuring 200px by 200px, that I would like to animate using CSS animations. The first box (upper box) should rotate from rotateX(0deg) to rotateX(90deg) with a transform-origin of center top. The second box should follow the bottom ...

What is the highest possible z-index value that can be applied in

Is there a specific limit to the CSS property z-index? Are there variations in accepted values among different browsers? How do browsers typically handle extreme z-index values? I recall reading about a potential maximum value for z-index somewhere, but I ...

Successfully retrieves the appropriate response, however the MySQL database fails to update when using PHP

I'm currently in the process of developing a straightforward registration form. I have a file dedicated to connecting to the database conn.php <?php $db_name = "bp_reader"; $mysql_username = "root"; $mysql_password = ""; $server_name = "local ...

What exactly is the significance of "utilizing a universal class name"?

In my current project, I am utilizing Material-UI version 3.1.2 to create the interface. Previously, when I was using Bootstrap4, I included style="overflow-y: scroll; height: 100%" in my head tag to ensure a scrollbar is always present, preventing the ap ...

Having issues with email verification and the length of phone numbers not functioning properly

I need to validate two text fields before registration: the email must be in correct format and the number must have exactly 11 digits. Any mismatches should trigger an error message. For the email validation, I used a function that checks for the require ...

A method to ensure that inline <div> elements occupy the entire available width

The typical solution for this issue is using float, however, it does not work in my situation. I attempted to utilize flexbox and overflow:hidden for the parent element, but unfortunately, it did not resolve the issue. Currently, I am dealing with three i ...

What is the best way to incorporate the :after pseudo-element in JavaScript code

HTML: This is my current code snippet <div class="one"> Apple </div> I am looking to dynamically add the word "juice" using JavaScript with the .style property. Is there an equivalent of :: after in CSS, where I can set the content in JavaS ...

Construct a structure containing the key/value pairs of cells within an HTML table row using JavaScript

I'm completely new to JavaScript so please be patient with me; I'm not even sure if I'm searching for the solution correctly. Despite spending hours googling and experimenting, I still can't get it to work. My issue is related to an HT ...

The table row's background image splitting into two halves

I am working on a table row class called logo, which has specific attributes. .logo { background: url("img/logo.png") no-repeat left top !important; } Currently, I have successfully placed an image at the top left of every row. However, my goal is ...

Combining various viewpoints into one cohesive SVG

Is there a way to create multiple unique perspectives within a single SVG, or replicate that effect using smart grouping techniques? I aim to display various sections of a potentially extensive SVG without the need for multiple renderings. Is there a str ...

Display a div with a link button when hovering over an image

Currently, I'm attempting to display a link button within a div that will redirect the user to a specified link upon clicking. Unfortunately, my current implementation is not functioning as expected. I have provided the code below for reference - plea ...

The div remains unchanged when the button is clicked

My webpage is filled with several large div elements. There's a button on the page that, when clicked, should switch to the next div. Despite my efforts, the code I've written doesn't seem to be working as expected. :( This is the HTML st ...

Angular 11.0.3 displaying ngClass issue (Unable to bind ngClass as it is not recognized as a property of div)

While working on an angular project, I implemented a light and dark theme using mat-slide-toggle to switch between themes. The theme is stored as a boolean called isDark in a Behavioral Subject service. There are two lazy-loaded modules - one for the home ...

Learn the process of extracting data from dynamically generated elements in JavaScript

I am a beginner in Javascript and Jquery and have recently started exploring business rules with Chris Powers. https://github.com/chrisjpowers/business-rules My current project involves adding a range slider for numbers and a number spinner. I attempted us ...

Dynamic font sizing in CSS allows text on a webpage to

I am working on creating a dynamic screen using AngularJS. Within this screen, there are objects with a specific size: .item { margin: auto; margin-bottom: 10px; width: 11vw; height: 11vw; text-overflow: ellipsis; overflow: hidden; } These i ...

Conceal descendant of list item and reveal upon clicking

In my responsive side menu, there is a submenu structured like this: .navbar ul li ul I would like the child menus to be hidden and only shown when the parent menu is clicked. Although I attempted to achieve this with the following code, it was unsucces ...

Fetching images from the resources or assets while the webpage is being loaded in a webview from the server

I am facing a challenge with sending a webpage from a server to WebView components on Android devices. While I have figured out how to establish communication between the webpage and the JavaScript handler in order for the native application to interact wi ...

What steps can I take to stop text from disappearing when the screen size decreases and the span is used?

I'm currently using Bootstrap 5 to create a form. On a computer screen, my file input element looks like this: https://i.sstatic.net/fX6Kx.png However, on mobile devices, it appears like this: https://i.sstatic.net/ilUZ9.png Below is the code sni ...

Selenium in Python is throwing a TypeError containing the message: "'str' object is not callable" when attempting to use the text()

links = browser.find_elements_by_xpath("//h2[@class='result-firstline-title highlighted-domain-title']//a") results = [] for i in range(len(links)): title = links[i].text() href = links[i].get_attribute("hre ...

"Customize file selection options with JFileChooser filters

I incorporated a JFileChooser into my program, but it only accepts images. To address this issue, I decided to implement filters: Code import javax.swing.*; public class fileChooser { public static void main(String[] args) { JPanel panel = new JPane ...