简体   繁体   English

如何对齐菜单项

[英]how to align menu items

I am just working on an eCommerce site where I am trying to create a mega menu using CSS MEGA SITE NAVIGATION from Codyhouse .我只是在一个电子商务网站上工作,我正在尝试使用来自 Codyhouse 的 CSS MEGA SITE NAVIGATION创建一个大型菜单

Everything is perfect except the horizontal alignment of the 2nd level menu.除了二级菜单的水平对齐外,一切都很完美。

I tried positioning list but there is no use.我试过定位列表但没有用。 Can anyone guide me to solve this?谁能指导我解决这个问题?

In this situation, the issue is that float: left;在这种情况下,问题是float: left; will continue to try and float as it moves down the page, taking the easiest option first (there's room at column 6, that's why it's chosen that one).将继续尝试在页面向下移动时浮动,首先选择最简单的选项(第 6 列有空间,这就是它选择那个选项的原因)。

So, in addition to floating I would instruct the 8th column to clear each of the first 7 items, no matter their height.因此,除了浮动之外,我还会指示第 8 列清除前 7 个项目中的每一个,无论它们的高度如何。

I can't see what your HTML structure is but something like this should do the trick.我看不到你的 HTML 结构是什么,但像这样的东西应该可以解决问题。 Replace li whatever child element you're using.替换li您正在使用的任何子元素。

li:nth-child(7n + 8){
  clear: both;
}

To explain: 7n is the number of columns you want to have before starting a new row, and 8 is targeting the next column as you want this one to clear all of the first row's children.解释一下:7n 是您在开始新行之前想要拥有的列数,8 是针对下一列,因为您希望这列清除第一行的所有子行。

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

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