首先放置您的右侧浮动元素,从and 中删除float: left;
并添加:http: //jsfiddle.net/mdares/kGkRD/1/width: 100%;
section.main
overflow: hidden;
HTML:
<aside class="sidebar">
Hello World
</aside>
<section class="main">
Hello World
</section>
CSS:
body {
max-width: 500px;
width: 100%;
margin: 0 auto;
}
section.main {
max-width: 300px;
background-color: red;
overflow: hidden;
}
aside.sidebar {
float: right;
width: 200px;
background-color: blue;
}
更新:我理解正确吗,您正在寻找这个:http: //jsfiddle.net/mdares/kGkRD/4/
body {
max-width: 500px;
width: 100%;
margin: 0 auto;
}
section.main {
max-width: 300px;
width: 100%;
background-color: red;
overflow: hidden;
float: left;
}
aside.sidebar {
float: left;
width: 200px;
background-color: blue;
}
如果是这样,你只是想念你的overflow: hidden;
更新 2:要解决您的评论,请尝试以下操作:http: //jsfiddle.net/mdares/kGkRD/5/
CSS:
body {
max-width: 500px;
width: 100%;
margin: 0 auto;
}
#container {
position: relative;
width: 100%;
}
section.main {
max-width: 300px;
width: 100%;
background-color: red;
overflow: hidden;
float: left;
}
aside.sidebar {
width: 200px;
background-color: blue;
position: absolute;
right: 0;
}
@media screen and (max-width: 350px) {
aside.sidebar {
position: static;
float: left;
}
}
HTML:
<div id="container">
<section class="main">
Hello World
</section>
<aside class="sidebar">
Hello World
</aside>
</div>