Achieving alignment of the avatar circle and text content using CSS

I am looking to properly align the text content and the avatar circle. Below are the classes that I have defined

.user-detail {
    display: inline-block;
    text-transform: uppercase;
    text-align: right;
    
    .user-detail__username {
        margin: 18px 16px 0px 10px;
        display: block;
        float: left;
        font-size: $font-size;
        font-weight: 500;
    }
    .user-detail__role {
        margin: 18px 16px 0px 10px;
        display: block;
        font-size: $font-size * 0.9;
        font-style: normal;
        line-height: 13px;
        font-weight: 300;
    }
    .user-detail__avatar-circle {
        display: inline-block;
        margin: 8px 11px 0px 0px;
        width: 45px;
        height: 45px;
        border-radius: 50%;
        border: 1px solid $lightstroke;
    }
    .user-detail__avatar {
        position: relative;
        font-size: 51px; 
        line-height: 43px; 
        left:-4px;
    }
}

and here is the HTML markup

<div class="user-detail right">
    <div style="display:inline-block">
        <span class="user-detail__username">
            Adminstrator
        </span>
        <span class="user-detail__role">Adminstrator</span>
    </div>

    <div class="user-detail__avatar-circle">
        <i class="material-icons user-detail__avatar">account_circle</i>
    </div>
</div>

it appears like this here

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

In order to achieve my desired look, I need the text and avatar circle to be bottom aligned. Upon inspecting the element, I noticed some space on top of the text div. I have attempted to adjust the margin of the text div but it does not seem to resolve the issue. Any suggestions on how to address this spacing problem?

Answer №1

Flexbox makes achieving layouts that are difficult with traditional CSS (such as using float, margin, inline-block, etc.) a piece of cake.

.user-detail {
  width: 300px;
  height: 100px;
  border: blue solid 2px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-detail>div {
  border: green solid 2px;
}

.user-detail .details {
  display: flex;
  flex-direction: column;
}
<div class="user-detail right">
  <div class="details">
    <span class="user-detail__username">
            Adminstrator
        </span>
    <span class="user-detail__role">Adminstrator</span>
  </div>

  <div class="user-detail__avatar-circle">
    <i class="material-icons user-detail__avatar">account_circle</i>
  </div>
</div>

Answer №2

Using Flexbox can simplify your layout process and reduce headaches. Check out this example:

.user-info {
   display: flex;
   flex-direction: row;
   justify-content: space-between;
   align-items: center;
}

For more information on Flexbox, visit: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

Answer №3

The vertical-align: top property typically aligns and positions your div element at the top, in this case the text "Administrator".

To make the necessary change in your HTML, reference the second <div> tag in the code snippet below,

<div class="user-detail right">
    <div style="display:inline-block;vertical-align: top">
        <span class="user-detail__username">
            Administrator
        </span>
        <span class="user-detail__role">Administrator</span>
    </div>

    <div class="user-detail__avatar-circle">
        <i class="material-icons user-detail__avatar">account_circle</i>
    </div>
</div>

I hope this solution proves helpful to you!

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

Struggling to keep navbar fixed with a blur effect without it colliding with body content as you scroll?

I'm looking to create a sticky navbar with a blur effect similar to the one seen on (try scrolling to see the blur effect on the nav). I want it to have the following structure: My HTML code is as follows: <header class="sticky z-10 top-10"> ...

Seeking feedback: Creating unique HTML markup using PHP, with the option of adding tag prefixes

After working on a PHP class that enables the creation of custom HTML markup similar to FB Markup or EE tags, I am now contemplating enhancing it further. The current functionality is based on tag prefixes like this: <ctag:pagination per_page="20" tota ...

What is the best way to define the relative path and folder paths in HTML and CSS when working in Visual Studio 2012?

Working on a basic HTML project that includes css and javascript. Within the project folders named css, scripts, and images are used for organization. The project structure can be seen in the provided image. https://i.sstatic.net/OwCSL.jpg The issue that ...

Issues with Angular-Trix compatibility with Internet Explorer 10

I am currently using the Angular-trix rich text editor, which is functioning perfectly in all browsers including IE 11. However, I am encountering issues with it not working in IE10 or earlier versions. An error message that keeps appearing states: Una ...

Adaptive Positioned Image Display

I currently have a Section with four blocks of content. Along the right-hand side of the screen, there are some images (as shown in this example) that I want to position absolutely. However, I am encountering an issue where these images overlap with the te ...

The z-index property in jQuery dialog does not seem to function properly when used within an

When using bootstrap with jQuery dialog, I encountered a strange issue. If the z-index of the dialog is set to 1 or higher in a standalone script, everything works fine. However, when the same script is called inside an iframe, the dialog ends up appearing ...

Difficulty Aligning Angular Material Expansion Panel with mat-nav-listI am facing an issue with

Currently, I have implemented a mat-nav-list to showcase the Menu items on my webpage. However, there seems to be an alignment issue with the 4th Menu item which is an Angular Material Expansion control. Refer to the screenshot provided below for clarifica ...

Accessing new information seamlessly without the need for page refresh

For optimal mobile viewing of my website, I am considering implementing a select element. Here are the available options: HTML: <select name="select-choice-8" id="select-choice-nc"> <optgroup label="News"> & ...

To view the following set of three images, simply click on the "load more" button

I'm looking to add a load more button to reveal additional images. Currently, the page loads with 3 images visible, and upon clicking the load more button, the next set of 3 images should be displayed on the screen. Unfortunately, the code I've ...

Problems Arising from Bootstrap Label and Input Field Alignment

I'm encountering an issue with my Angular app that uses Bootstrap 4. I'm trying to have my form label and input text box appear on the same line, but instead, they are displaying on separate lines. I've tried searching for a solution, but ha ...

My HTML file is experiencing issues with the Bootstrap model implementation

I have integrated the CDNs (CSS/JS) provided by Bootstrap into my HTML file. I then copied and pasted the code for a demo modal from their website into the body tag. However, when I view the page in the browser and click on the button, the modal does not ...

accommodating multiple background images in CSS

I am currently working on a WordPress website using the Twenty Twelve theme. On one of the pages, I am trying to incorporate three background images - one at the top, the next one right below the top image, and the third one at the very bottom... Is there ...

implementing a button's decrease and increase functionality in JavaScript

Whenever the button is clicked, it changes its color to red. Additionally, a counter increments with each click. However, I want the counter to be dynamic so that when the button is unclicked, the counter decreases as well. Unfortunately, I am facing diffi ...

Enhance your Divi theme with Elegant Themes: Explore mobile-friendly background image zoom effects

I have a regular section module with an image as the background. The design looks great on desktop but appears zoomed in and blurry on mobile devices. I'm struggling to understand why the mobile view is not adjusting properly, and I am unsure if there ...

The background color of the CSS div tag does not cover the entire axis

I'm facing a dilemma in my CSS design that's got me stuck. This issue also seems to be present in this forum: Whenever I zoom in on the page, I noticed that the header background doesn't fully extend across the screen horizontally. Here&apo ...

Steps for assigning innerHTML values to elements within a cloned div

Currently, I am setting up a search form and I require dynamically created divs to display the search results. The approach I am taking involves: Creating the necessary HTML elements. Cloning the structure for each result and updating the content of ...

Editing Files on Your Computer Using a Website

My objective is to enable users to edit either a json file located in the same folder or the current web page in a way that remains persistent for all users accessing the page. The challenge lies in the fact that it is hosted on a local smb over which I ha ...

Stacking of div tags on top of each other

Looking for assistance with some CSS challenges. I am attempting to design a group of buttons using div tags, but they are all merging into one another. You can find the code at http://codepen.io/CliffTam/pen/gadEaq Could someone review the code and pro ...

Arrange a row of six images side by side using responsive Bootstrap styling

Struggling to align 6 images in one row using bootstrap, but only getting 4 images with a large space between them. CSS isn't my strong suit. Here's the HTML Code: <html> <head> <link href="https://maxcdn.bootstrapcdn.com/bootstr ...

100% width with a pixel offset

In the past, I have achieved this by using padding. The concept is to have two div elements positioned side by side, where one has a width of 100% and the other has a fixed width of 50px. Here's a rough illustration: ------------------------------- ...