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 can I create a centered responsive menu

I have some troubles creating a menu that has 4 items and should be be centered beside each other with a gap between them, and if on mobile device be stacked on each other. The menu should look like the image here…

enter image description here

Can someone please show how this can be achieved?

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 :

It is possible to do so, just with a ul list and few lines of CSS:

<!DOCTYPE HTML>

<html>

    <head>
        <style>

            * {
                margin: 0;
                padding: 0;
            }
            .menu {
                list-style-type: none;
                width: 100%;
                text-align: center;
            }
            .menu li {
                text-align: center;
                display: inline-block;
                padding: 8px 16px;
                margin: 8px 8px;
                background-color: rgba(0, 0, 255, 0.336)
            }

            @media only screen and (max-width: 600px) {
            
                .menu li {
                    display: block;
                }

            }

        </style>
    </head>

    <body>
        
        <ul class="menu">
            <li>Menu1</li>
            <li>Menu2</li>
            <li>Menu3</li>
            <li>Menu4</li>
        </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