It seems like there are a few issues here, and I'm not entirely clear on your intended outcome. Providing an image of the desired design would be beneficial in clarifying the goal. That being said, I'll do my best to address what I can.
One problem is that your v-for
directive is placed on the #first
div, resulting in multiple instances of #first
for each user in the getUsers
array. As IDs should be unique, having multiple #first
IDs will cause the names to stack instead of flexing properly within each .names
element. The generated markup looks like this:
<div class="main-browser">
<div id="first" class="names">
<div id="user">H</div>
</div>
<div id="first" class="names">
<div id="user">L</div>
</div>
<div id="first" class="names">
<div id="user">N</div>
</div>
<div id="first" class="names">
<div id="user">K</div>
</div>
</div>
To resolve this issue, it's recommended to move the v-for
onto the #user
element rather than #first
, and use classes instead of IDs. A revised markup example could look like this:
<div :style="image" class="main-browser">
<div class="names">
<div
v-for="(user, index) in getUsers"
:key="user.id"
class="user"
:style="{backgroundColor: getColors[index]}">
<div>{{user.name[0]}}</div>
</div>
</div>
</div>
This updated structure would render as follows:
<div class="main-browser">
<div class="names">
<div class="user">H</div>
<div class="user">L</div>
<div class="user">N</div>
<div class="user">K</div>
</div>
</div>
By making these adjustments, you can iterate through the users correctly and have more flexibility in rendering their information.
Additionally, don't forget to apply display: flex;
to the .names
class to ensure the initials display next to each other in a row.
In regards to your question about having items in one div display separately in different positions, the approach will vary based on your specific requirements. If you simply want them to display side by side, the changes suggested above should suffice, though you may need to adjust margins for proper alignment.
If you need more precise positioning, consider using position: relative;
on .names
and then applying position: absolute;
to its child elements. You can then customize the positioning using properties like top
, right
, bottom
, and left
.