好的,所以我认为这对您来说是最快的解决方法。您已经有了一个很棒的 html 结构,但我将为您缩小范围。这是JsFiddle。
使用您的代码:
#maincontainer {
width:100%;
height: 100%;
}
我做了这样的小调整:
#maincontainer {
width:100%;
height: 100%;
display:inline-block;//added this
}
然后我还像这样重组了另外两件事:
#leftcolumn {
float:left;//added this
width: 100px;
height:100%;
background: blue;
}
#contentwrapper {
float:right;//added this
width:100%;
height: 100%;
background-color: red;
}
现在在这个 JsFiddle 中,我已经适当地创建了一个特定的宽度,因此您可以随时更改它。请记住,如果您使用 100% 作为宽度,并尝试在同一行粘贴其他内容,它会自动创建两条线,如下所示:
#leftcolumn {
display:inline-block;<-- changed this above.
width: 100px;<----This won't work with the below
height: 100%;
background: blue;
}
#contentwrapper {
display:inline-block;<---- changed this above.
width:100%;<---- This won't work with the above
height: 100%;
background-color: red;
}
但如果你将其重组为更像这样:
#leftcolumn {
display:inline-block;
width: 10%;<---This will work with the below
height: 100%;
background: blue;
}
#contentwrapper {
display:inline-block;
width:90%;<---This will work with the above.
height: 100%;
background-color: red;
}
有几点需要注意,我确实使用 JsFiddle 添加了高度,以便我可以看到实际尺寸,并且出于确切原因我还添加了宽度。需要注意的是可以真正帮助实现,基本的“为什么这样做”是this。
如果有什么不适合你的,请在下方评论:)