我创建了一个菜单 div。在这个 div 中,我想在左侧添加几个列表项和一个 Logo 。
但是,例如,当我给菜单项填充或高度时,它们会像 js fiddle 中所示那样超出菜单 div。这些元素不应超出其父级。
最佳答案
你应该使用 float 元素而不是你给菜单元素的边距
#logo {
height:50px;
width:80px;
background-color:red;
float:left; // add this
}
#menu ul {
// margin-left:70%; // remove this
float:right; // add this
position: relative;
line-height: 100px;
}
https://jsfiddle.net/c6tp9zmx/1/
关于html - div 中的元素未保持原位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37569073/