How to center navigation on page using ul list?
P粉052686710
P粉052686710 2023-08-13 11:06:53
0
1
475

如何在页面上水平和垂直居中ul列表中的导航?

以下是HTML和CSS代码


.nav{ width: 100%; height: 100%; position: fixed; background-color: white; overflow: hidden; } .menu a{ padding: 30px; color: black; text-align: center; left: 0; margin: 0 auto; flex: none; display: flex; align-items: center; justify-content: center; }


我尝试使用CSS的flex方法来对齐项目。

P粉052686710
P粉052686710

reply all (1)
P粉642436282

You must apply flexbox properties to the container containing the item, not the item itself.

.nav { width: 100%; height: 100%; position: fixed; background-color: white; display: flex; align-items: center; justify-content: center; } .menu { list-style-type: none; padding: 0; } .menu a { padding: 30px; color: black; text-align: center; text-decoration: none; }

This will center your ul horizontally and vertically in the .nav container.

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!