Solution 1 :

Use the flex rule for selector .navsection. It should look like this:

.navsection {
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: cadetblue;
}
.navsection{
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: cadetblue;
}

.navsection ul{
    margin: 0;
    padding: 0;
    list-style: none;
    
    /* display: table;
    margin: 0 auto; */
}
.navsection ul li{
   display: block;
   float: left; 
   
}
.navsection ul li a{
    text-decoration: none;
    color: rgb(116, 4, 26);
    display: inline-block;
    padding: 10px 20px;
    background: rgb(127, 210, 212);
    margin: 5px 2px;
}
<div class="navsection tem clear">
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Gallery</a></li>
        </ul>
</div>

second solution (no flex):

Remove the float: left and make display: inline-block instead of display: block in the .navsection ul li selector.

It should be like this:

.navsection ul li{
   display: inline-block;
   /*float: left; */   
}
.navsection{
    background-color: cadetblue;
    text-align: center;
}

.navsection ul{
    margin: 0;
    padding: 0;
    list-style: none;
    
    /* display: table;
    margin: 0 auto; */
}

.navsection ul li{
   display: inline-block;
   /*float: left; */   
}

.navsection ul li a{
    text-decoration: none;
    color: rgb(116, 4, 26);
    display: inline-block;
    padding: 10px 20px;
    background: rgb(127, 210, 212);
    margin: 5px 2px;
}
<div class="navsection tem clear">
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Gallery</a></li>
        </ul>
</div>

Problem :

I’ve tried like this. how can I center list items inside the div?

.navsection{
    background-color: cadetblue;
    text-align: center;
}

.navsection ul{
    margin: 0;
    padding: 0;
    list-style: none;
    
    /* display: table;
    margin: 0 auto; */
}
.navsection ul li{
   display: block;
   float: left; 
   
}
.navsection ul li a{
    text-decoration: none;
    color: rgb(116, 4, 26);
    display: inline-block;
    padding: 10px 20px;
    background: rgb(127, 210, 212);
    margin: 5px 2px;
}
<div class="navsection tem clear">
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Gallery</a></li>
        </ul>
    </div>

I’ve tried to put the ul tag inside the div and then take it to the center. so I make the text-align center. but it’s not working. why this is not working? I’ve tried to put the ul tag inside the div and then take it to the center. so I make the text-align center. but it’s not working. why this is not working?

Comments

Comment posted by Al Arefin

Thanks, and will you please tell How can I take it to the right?

Comment posted by s.kuznetsov

Try

Comment posted by s.kuznetsov

I gave you a second solution without

By