Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个与左侧对齐的垂直侧边栏导航菜单,其宽度为 211 像素,高度为 300 像素。然后我有一个 960px 宽的容器。由于边栏占用了 211px 的屏幕宽度,当我使用 margin: 0 auto; 将其居中时,容器与它重叠。
如何将容器从导航菜单而不是一般屏幕宽度居中,并且解决方案将在所有浏览器/平台的导航菜单中居中显示?
用另一个 div 包装容器(例如.wrapper)。使包装器总视口宽度减去侧边栏宽度的宽度,然后margin:0 auto在容器中使用
.wrapper
margin:0 auto
示例::小提琴