Home > database >  how to make a li tag horizontal while its a block
how to make a li tag horizontal while its a block

Time:03-09

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  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 >
        <li ><div  >0</div></li>
        <li ><div >0</div></li>
        <li  style="float:right"><a>EFOOTBALL</a></li>
    </ul>

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

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

CodePudding user response:

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  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 >
        <li ><div  >0</div></li>
        <li ><div >0</div></li>
        <li  style="float:right"><a>EFOOTBALL</a></li>
    </ul>

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

  • Related