简体   繁体   English

如何将 HTML 中的列表项居中

[英]How To Center A List Item in HTML

I'm trying to start off with a simple website and I want to know how I can fix my navigation bar since I accidentally messed up my code leaving it in a misaligned state.我试图从一个简单的网站开始,我想知道如何修复我的导航栏,因为我不小心弄乱了我的代码,使其处于未对齐状态。 I seem to have checked my CSS properly and I don't see anything wrong with it.我似乎已经正确检查了我的 CSS,但我没有发现它有任何问题。

From what I've done, I double checked to make sure I remembered to close my tags and check the CSS.根据我所做的,我再次检查以确保我记得关闭我的标签并检查 CSS。

 #mainnav { margin: 0 auto; padding: 0; text-align: center; } #mainnav ul { display: inline-block; list-style: none; } #mainnav ul li { float: left; margin: 0px 20px 0px 0px; /* spacing in-between the boxes */ padding: 10px 20px 10px 20px; /* spacing inside the boxes */ }
 <nav> <div id="mainnav"> <ul> <li><a href="index" class="nav-home">HOME</a></li> <li><a href="about-me.html" class="nav-about-me">ABOUT ME</a></li> <li><a href="vpnhole.html" class="nav-vpnhole">VPNHOLE</a></li> <li><a href="projects.html" class="nav-projects">PROJECTS</a></li> <li><a href="misc.html" class="nav-misc">MISC.</a></li> </ul> </div> </div> </nav>

I expected the output of the navigation links to be aligned where one link is aligned to the a picture in the website, but the actual output turned out to be off by a couple centimeters.我希望导航链接的输出对齐,其中一个链接与网站中的图片对齐,但实际输出结果偏离了几厘米。

If I correctly understood the task - it should help如果我正确理解了任务 - 它应该会有所帮助

ul{
    padding: 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM