CSS padding keeps inheriting

喜欢而已 提交于 2019-12-13 06:08:05

问题


I'm making a dropdown menu, but all the styles from the first ul is being added to the styles on every ul beneath the first ul.

I've tried overriding the styles using !important, and moving the css to different levels. Anyone got a clue about whats going on here?

This image probaly explains it the best way: http://screencast.com/t/UrkRbjjaYctp

Thanks.


回答1:


#menuwrapper > ul{
padding-left:37px;
}
#menuwrapper ul ul {
padding-left:40px;
}

This should solve your issue




回答2:


This is expected behavior. Paddings are added relatively.

If you don't want the nested ul to be padded 37px you have to remove the padding from parent ul (or use some hack as negative margin e.g. margin-left: -37px).

If you remove padding from the parent you will probably need to add some margin to each its child to preserve the layout. I'd suggest to reconsider the HTML structure.



来源:https://stackoverflow.com/questions/15761331/css-padding-keeps-inheriting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!