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 list item in the center of the screen?

I’m confused why my list items is not really in center of the screen. The list items should be in the center of the screen if i use "align-items: center;" but it’s not work perfectly.

<!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>Anagram - Single Player</title>

    <style>
        body {
            background:linear-gradient(180deg, rgba(83,49,128,1) 0%, rgba(125,74,149,1) 35%, rgba(164,104,169,1) 100%);
            width:100vw; height:100vh;
            margin: 0;
            padding: 0;
        }

        .list {
            display: flex;
            flex-direction: column;
            top: 50%;
            left: 50%;
            position:absolute;
            transform: translate(-50%,-50%);
            align-items: center;
            background: blue;
        }

        .list ul li {
            list-style-type: none;
            display: inline-block;
            padding: 10px;
            border-radius: 5px;
            background: black;
            width: 32px;
            text-align: center;
            margin: 4px;
        }

        .list ul li a {
            text-decoration: none;
            color: white;
            font-size: 30px;
        }
    </style>
</head>
<body>
    <div class="list">
        <ul id="button-list"></ul>
    </div>

    <script>
        let ul = document.getElementById("button-list");
        let word = "MAMALIA";

        for(var i=0; i<word.length; i++){
            let li = document.createElement("li");
            li.innerHTML = "<a href='#'>" + word[i] + "</a>";
            ul.appendChild(li);
        }
    </script>
</body>
</html>

I have try using align items, justify content, and transform. I still can’t make it really in the center of the screen.

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 :

Just add padding: 0; in the ul.

 .list ul {
     padding: 0;
  }
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