Display the images adjacent to the usernames, followed by their respective levels underneath

<div class="players">
    {{#each users}}
        {{#each usersInLobby}}
        <img src="/img/characters/{{skin}}.png" style="height: 85px; display:inline;">
            <p>{{username}}{{level}}</p>
        {{/each}}
    {{/each}}
</div>

This is the current version of my code. However, it is displayed like this:

I would like to have the usernames displayed below the images and the images displayed inline.

Answer №1

There are multiple methods to accomplish your goal. Here are a couple of examples:

Implementation of display: inline-block;

.player {
  margin: 10px;
  border: 1px solid red;
  padding: 10px;
  text-align: center;
  display: inline-block;
}
<div class="players">
    <div class="player">
        <img src="https://picsum.photos/100">
        <p>Username - Level</p>
    </div>
    
    <div class="player">
        <img src="https://picsum.photos/100">
        <p>Username - Level</p>
    </div>
</div>

Utilizing display: flex;

.players {
  display: flex;
}

.player {
  margin: 10px;
  border: 1px solid red;
  padding: 10px;
  text-align: center;
}
<div class="players">
    <div class="player">
        <img src="https://picsum.photos/100">
        <p>Username - Level</p>
    </div>
    
    <div class="player">
        <img src="https://picsum.photos/100">
        <p>Username - Level</p>
    </div>
</div>

Both options require wrapping your elements within a parent div.

Answer №2

When you say "inline," are you referring to centering the content? If so, consider using this code snippet:

<div class="players">
    {{#each users}}
        {{#each usersInLobby}}
            <img src="/img/chars/{{skin}}.png" style="height: 85px; margin-right: 0px; margin-left: 0px;">
            <p>{{username}}{{level}}</p>
        {{/each}}
    {{/each}}
</div>

Answer №3

To enhance the layout, consider enclosing the img and p elements within a single div and then use the inline-block property on the wrapping div:


    <div class="players">
        {{#each users}}
            {{#each usersInLobby}}
                <div class="users">
                    <img src="/img/chars/{{skin}}.png" style="height: 85px">
                    <p>{{username}}{{level}}</p>
                </div>
            {{/each}}
        {{/each}}
    </div>

Add the following CSS:

.users{
    display: inline-block;
    vertical-align: top;
}

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

Exploring Angular 6: Unveiling the Secrets of Angular Specific Attributes

When working with a component, I have included the angular i18n attribute like so: <app-text i18n="meaning|description"> DeveloperText </app-text> I am trying to retrieve this property. I attempted using ElementRef to access nativeElement, bu ...

How can you conceal nested elements within a layout that adjusts to various screen sizes or is percentage-based

Contemplate this HTML: <body> <div id="parent"> <div id="child"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras dapibus sapien congue, fringilla justo quis, aliquam tellus. Maecenas semper consectetur metus ege ...

Can I use Javascript to access a span element by its class name?

Similar Question: How to Retrieve Element By Class in JavaScript? I am looking to extract the text content from a span element that does not have an ID but only a specific class. There will be only one span with this particular class. Can anyone guide ...

The "div width 100%" property functions flawlessly when tested locally, yet fails to operate on the live server

Hello, I recently launched my new website at www.leafletsdistributors.com. However, I'm encountering an issue with the Get in touch section (the light grey colored area). Despite setting the width to 100%, it's not fully extending across the scre ...

What is the method used by React or Next to prevent the <a> tag from refreshing the page while still loading content?

I'm currently diving into the world of NextJS and utilizing the Link component from the 'next/link' package. One thing that has been puzzling me is how the <Link> component ultimately renders an <a> tag with a href='/tosomew ...

Elements with absolute positioning are preventing drag events from executing

Struggling to create a slider and encountering an issue. The problem lies in absolute items blocking slider drag events. I need a solution that allows dragging the underlying image through absolute positioned items. Any ideas on how to achieve this? MANY T ...

Look up and input information into the dropdown selection list

Is there a way to search for and input text in a select drop-down menu? Generally, we are unable to write inside the select drop-down menu. Is there a method that allows me to type inside this drop-down menu and as I am typing, if a similar word appears, I ...

Modifying the HTML <select> element with JavaScript

[resolved] I'm encountering an issue with the code below that is supposed to dynamically change the options in a second drop-down menu based on the selection made in the first menu. I've tried to troubleshoot the problem but haven't been suc ...

Incorporating a CSS Module into a conditional statement

Consider the following HTML structure <div className={ `${style.cell} ${cell === Player.Black ? "black" : cell === Player.White ? "white" : ""}`} key={colIndex}/> Along with the associated CSS styles .cell { ...

The ng-repeat-start feature is not functioning properly across different levels

I am attempting to utilize the ng-repeat-start directive in order to construct a table that resembles the following: The structure of my JSON data is as follows: [ { "name": "Chapter 1", "parts": [ { "text": "Lorem ipsum... 1", ...

Arranging date and time in jQuery based on AM/PM notation

I have written some JavaScript code to sort dates in ascending order (from newest to oldest). I have successfully sorted the dates, but I am having trouble sorting the time with AM or PM using a 12-hour format. I can do it in a 24-hour format, but not in ...

How can I show the HTML text "<ahref>" in a UITextView on iOS?

Is there a way to show HTML tags like <a> in a textview? As an example, here is some code: Hello good morning <a href=\"1\">USER1</a> and <a href=\"13\">USER2</a> ...

outdoor checkboxes indicate completion

Whenever I click on the email address example [email protected], my first checkbox gets checked inexplicably... I have created a fiddle to demonstrate this issue... http://jsfiddle.net/pZ8jY/ <table class="checkboxes"> <tr> <td ...

Creating a carousel similar to the one on Skipperlimited's website can be achieved

I am working on a project and I would like to create a design similar to the one found at Specifically, I am interested in replicating the carousel of images and the rotating carousel within their logo. Can anyone provide guidance or suggestions on how to ...

Having trouble with getting the second JavaScript function to function properly?

I am facing an issue with the second JavaScript function. When I click the 'Send Mail' button, it should call the second function and pass it two values. However, the href line (second last line in the first function) is not rendering correctly. ...

Styles for Django Rest Framework admin interface are not displaying correctly

Has anyone else experienced an issue with the styling in their Django admin panel? The CSS appears to be functioning properly, but once you navigate to a specific model, the layout becomes distorted. I can't seem to figure out what could be causing th ...

Integrate CSS and JavaScript files into Node Express

I am facing an issue including my CSS file and JavaScript file in a node-express application, as I keep getting a 404 not found error. Here is the code snippet that I am using: 1. In server.js var http = require('http'); var app = require(' ...

Using a nested table will override the "table-layout: fixed" property

I'm currently working on creating a tabular layout and I'm in need of the following: 2 columns with variable widths Columns that are equal in width Columns that are only as wide as necessary After some research, I discovered that by setting "t ...

What is the best way to implement a new search input for my datatable while also enabling the searchHighlight feature?

I'm attempting to implement a search bar for my datatables. I need to hide the default search engine that comes with datatables, so I added a script that I found in a forum. However, when I try to run it in my code, it doesn't work and displays a ...

Creating a pull-up toolbar with just HTML and CSS for an Android browser

I need to create a draggable toolbar on my mobile webapp that can reveal content beneath it. I want to achieve this using just HTML/CSS, without relying on touch/scroll events or libraries. To do this, I'm overlaying a scrolling element on top of the ...