Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to make a li tag horizontal while its a block

I want to make a online card game with html/css/js and i want to make a place that shows all your cards but i want them to be inline and inline-block because i need to give it a custom width and height but when i do that it doesnt work

heres the code :

var players = 
[
    {
        "id":1,
        "name":"messi",
        "price":100

    },
    {
        "id":2,
        "name":"ronaldo",
        "price":100

    }
];

for (var i = 0; i<players.length; i++){
    document.getElementById('cards').innerHTML += `<li><div class="card" style="background-image: url('images/${players[i].name}.png');background-size: 80px 110px;"><h1>${players[i].name}</h1></div></li>`;
}
.coin{
    display: inline-block;
    margin-top: 5px;
    margin-left: 10px;
    text-align: center;
    width: 25px;
    height: 25px;
    background-color: gold;
    border-radius: 50%;
    box-shadow: 0 0 10px goldenrod;
}

.xp{
    display: inline-block;
    margin-top: 5px;
    margin-left: 10px;
    text-align: center;
    width: 25px;
    height: 25px;
    background-color: darkblue;
    border-radius: 50%;
    box-shadow: 0 0 10px blue;
}

.navbar{
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #333;
}
  
.nav-item {
    float: left;
}
  
.nav-item a {
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

.card{
    display: inline-block;
    width: 80px;
    text-align: center;
    height: 110px;
    border-radius: 5px;
    margin: 5px;
    color: #fff;
    font-size: 12px;
    box-shadow: 0 0 5px black;
}

.cards{
    list-style-type: none;
    display: inline;
    background-color: rgb(56, 56, 56);
    padding: 5px;
    margin: 20px;
    border-radius: 5px;
}

* {
    font-family: "Helvetica Neue",Helvetica,Arial;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
    <script src="script.js" defer></script>
</head>
<body style="background-color: rgb(53, 53, 53);">
    <ul class="navbar">
        <li class="nav-item"><div class="coin" >0</div></li>
        <li class="nav-item"><div class="xp">0</div></li>
        <li class="nav-item" style="float:right"><a>EFOOTBALL</a></li>
    </ul>

    <ul class="cards" id="cards">
        
    </ul>
</body>
</html>

if you run the snippet its not horizontal
please help me i need help fast

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Instead of making it inline u should make it display: flex

edit: to make cards go to next line use flex-wrap: wrap

var players = 
[
    {
        "id":1,
        "name":"messi",
        "price":100

    },
    {
        "id":2,
        "name":"ronaldo",
        "price":100

    }
];

for (var i = 0; i<players.length; i++){
    document.getElementById('cards').innerHTML += `<li><div class="card" style="background-image: url('images/${players[i].name}.png');background-size: 80px 110px;"><h1>${players[i].name}</h1></div></li>`;
}
.coin{
    display: inline-block;
    margin-top: 5px;
    margin-left: 10px;
    text-align: center;
    width: 25px;
    height: 25px;
    background-color: gold;
    border-radius: 50%;
    box-shadow: 0 0 10px goldenrod;
}

.xp{
    display: inline-block;
    margin-top: 5px;
    margin-left: 10px;
    text-align: center;
    width: 25px;
    height: 25px;
    background-color: darkblue;
    border-radius: 50%;
    box-shadow: 0 0 10px blue;
}

.navbar{
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #333;
}
  
.nav-item {
    float: left;
}
  
.nav-item a {
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

.card{
    display: block;
    width: 80px;
    text-align: center;
    height: 110px;
    border-radius: 5px;
    margin: 5px;
    color: #fff;
    font-size: 12px;
    box-shadow: 0 0 5px black;
}

.cards{
    list-style-type: none;
    display: flex;
    flex-wrap: wrap;
    background-color: rgb(56, 56, 56);
    padding: 5px;
    margin: 20px;
    border-radius: 5px;
}

* {
    font-family: "Helvetica Neue",Helvetica,Arial;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
    <script src="script.js" defer></script>
</head>
<body style="background-color: rgb(53, 53, 53);">
    <ul class="navbar">
        <li class="nav-item"><div class="coin" >0</div></li>
        <li class="nav-item"><div class="xp">0</div></li>
        <li class="nav-item" style="float:right"><a>EFOOTBALL</a></li>
    </ul>

    <ul class="cards" id="cards">
        
    </ul>
</body>
</html>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading