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:

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

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

Render data from a RESTful Express API using AJAX and Node.js to display on a webpage

New to node.js development and facing a specific issue. My goal is to build a single-page web app using node.js where users can submit request data, retrieve information from the IMDb API, and display it on the same page. Here's my code: server.js # ...

Ways to update the div's color according to a specific value

Below are the scripts and styles that were implemented: <script src="angular.min.js"></script> <style> .greater { color:#D7E3BF; background-color:#D7E3BF; } .less { color:#E5B9B5; background-co ...

Tips for determining what elements are being updated in terms of style

I need assistance with modifying the functionality of a webpage's dropdown menu. Currently, it displays when the mouse hovers over it, but I want to change it to appear on click using my own JavaScript. Despite setting the onmouseout and onmouseover e ...

Arranging Bootstrap Grids within Laravel

On my current web page, I have implemented Bootstrap Grids as seen in the image below. Check out My Bootstrap Grid Layout However, I am aiming to achieve a grid layout similar to the one shown in the picture with a red indicator. Here is the Desired Boo ...

Generate fresh input fields with distinct identifiers using JavaScript

My challenge is to dynamically create new empty text boxes in JavaScript, each with a unique name, while retaining the text entered in the previous box. I struggled with this for a while and eventually resorted to using PHP, but this resulted in unnecessar ...

I am looking to adjust the height of my MUI Grid component

Recently exploring React, and I'm looking to set a height limit for MUI Grid. I've structured my project into 3 sections using MUI grid components. My goal is to restrict the page height in order to eliminate the browser scrollbar. If the conten ...

Adjusting the transparency of the background without impacting the text itself

I've been struggling to create a loading screen with no luck. The animation itself looks fine, but the background is causing issues. Every time I try to adjust the opacity, it affects the text as well. @import url('https://fonts.g ...

Looking to incorporate multiple accordion drop down menus on your website? Utilize a combination of HTML, CSS, and JavaScript to

I am experiencing a challenge with implementing multiple accordion menus on my website. Whenever I attempt to duplicate the code, the new accordion menu appears but clicking on the first bar simply scrolls me back to the top of the webpage. Below is the H ...

Tips on incorporating a style-tag into the body of an Angular 5 application

We offer a service that collects a vast amount of data to be displayed in an angular 5 application. The model used for displaying this data is constantly evolving and shared across multiple applications, so I need to import it dynamically. My approach inv ...

Text that appears automatically in an input field

I've searched high and low, but I just can't seem to find a solution that works for me. What I need is a way to automatically populate a HTML text field with default text when the page loads. This default text should ideally be a PHP variable and ...

What are some methods for controlling a webpage? Is it through HTML, JavaScript, Xpath, or

Hey there, I could really use your expertise on untangling a question that has me completely stumped. What exactly is the mechanism for controlling a webpage? a. HTML b. JavaScript c. Xpath d. CSS ...

Error alert: Blinking display, do not dismiss

I am trying to make it so that when the "enviar" button is clicked, the "resultado" goes from being hidden ("display:none") to being visible ("display:block"). This is my html document: <script type="text/javascript"> function showResu ...

Implementing dynamic database content into a Wow Slider on a jQuery Mobile platform

I am currently using static data in a slider with wow slider jquery mobile. However, I would like to retrieve data from a database and display it in the slider. Can someone provide suggestions on how to do this? Thank you. <script type="text/javascri ...

What is the best way to enable CSS IntelliSense for a Nuxt project?

Currently, I am undertaking a project using Nuxt.js and have set up a Docker image to manage all aspects of it. Additionally, I am looking to integrate MDBVue as a CSS library into my project. After some research, I learned that in order to utilize this li ...

Saving the subtracted value from a span into a cookie until the checkbox is unchecked - here's how to

I am working on a piece of code that includes numeric values within a span. When the checkbox is clicked, it subtracts 1 from the main value, essentially reducing the total value. How can I achieve this so that even after the form is submitted, the deducte ...

Setting the height of a div tag in CSS/HTML5 to match the current height of the browser window

Is there a way to make the height of my div tag always equal to the height of the browser's window, so it adjusts automatically when the browser is resized? I have tried using .class { height: 100%; } But this doesn't work. I've learne ...

How can we save the final composite image created with image layers, Cufon, jQuery,

I'm currently exploring the possibility of a new idea, but I'm not entirely certain if it can be achieved. My progress so far involves loading an image from a URL and using jQuery UI draggable feature to enable users to drag HTML text (which has ...

Posting data using the form method="post" in Vue does not seem to be working

My goal is to create a website that allows users to reserve a seat using a specific password and time slot. I've set up a form where users can input the password and their name, then submit the form to make the reservation. However, I'm facing an ...

Display an Asterisk Icon for md-input fields with lengthy labels

Documentation states that md-inputs add an asterisk to the label if it is a required type. However, when input containers have width constraints and long labels, the label gets truncated and the asterisk becomes invisible. From a user experience perspectiv ...

Creating movement in an SVG patterned background

Currently in the process of designing a brand new website using NextJS and Tailwind. I am looking to incorporate an infinitely translating background effect that moves towards the bottom right, similar to this example (but with my own unique pattern): htt ...