[英]horizontal menu in html displaying wrong while removing float property in css
I have a website build in HTML and CSS, now I am making small changes to the template as I bought it from Envato, the header menu is aligned to the left by default using the following CSS:我有一个使用 HTML 和 CSS 构建的网站,现在我正在对从 Envato 购买的模板进行一些小的更改,默认情况下,标题菜单使用以下 CSS 向左对齐:
.horizontalMenu>.horizontalMenu-list { text-align: left; margin: 0 auto 0 auto; width: 100%; display: block; padding: 0; } .horizontalMenu>.horizontalMenu-list>li { text-align: center; display: block; padding: 0; margin: 0; float: left; padding: 0.45rem 0; }
now I want to make the menu to come in the center so I removed the float property from the CSS and now the menu is displaying like below:现在我想让菜单位于中心,所以我从 CSS 中删除了 float 属性,现在菜单显示如下:
can anyone please tell me what could be wrong here or how to fix it, thanks in advance任何人都可以告诉我这里可能有什么问题或如何解决它,提前致谢
The nav items are aligned vertically because nav-item display
CSS attribute is block
.导航项垂直对齐,因为导航项
display
CSS 属性是block
。 So it's aligned one on one line.所以它是一对一对齐的。
Simply, to align items on the center, you can use flex
layout as follows.简单地说,要在中心对齐项目,您可以使用
flex
布局,如下所示。
.horizontalMenu>.horizontalMenu-list {
text-align: left;
margin: 0 auto 0 auto;
width: 100%;
padding: 0;
display: flex;
justify-content: space-between;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.