这一次击败了我,我相信我错过了一些简单的东西。
我想做的是有一个固定宽度的左侧边栏和右填充可变宽度的内容,将处理响应设计。
复杂的是,我希望左侧侧边栏的HTML位于右div之后,这样当分辨率降到移动大小时,我就可以删除浮动,并将内容显示在侧边栏前面,并且两者都具有100%的宽度。
.header {
width: 100%;
background-color: green;
}
.content {
background-color: red;
height: 100px;
float: right;
}
.sidebar {
background: blue;
width: 240px;
height: 100px;
}
@media (max-width: 750px) {
.content {
float: none;
width: 100%;
}
.sidebar {
width: 100%;
}
}<div class="header">Top</div>
<div class="content">Content (right on widescreen, top on less than 750px</div>
<div class="sidebar">Sidebar (left on widescreen, bottom on less than 750px</div>
发布于 2014-10-09 10:41:23
您可以使用calc() .Just将其添加到.content宽度: calc(100% -240 be );您将使内容响应并占用剩余的宽度。
示例http://jsfiddle.net/a5LLhmo8/1/
.header {
width: 100%;
background-color: green;
}
.content {
background-color: red;
height: 100px;
float: right;
width: calc(100% - 240px);
}
.sidebar {
background: blue;
width: 240px;
height: 100px;
}
@media (max-width: 750px) {
.content {
float: none;
width: 100%;
}
.sidebar {
width:100%;
}
}您可以阅读更多关于它的这里。
发布于 2014-10-09 10:58:07
我想我明白了!
请核对:
@media (max-width: 750px) {
.content {
float: none;
width: 100%;
position: relative;
}
.sidebar {
width:100%;
float: ;
position: absolute;
bottom: 0;
}请查看链接,看看这是否是您要查找的内容:
http://jsfiddle.net/a5LLhmo8/2/
我希望这能帮到你。
发布于 2014-10-09 10:59:25
您也可以使用柔性盒设计,使您的页面响应无需使用媒体查询,它可以提供很大的灵活性。
HTML:
<div class="header">Top</div>
<div class="container">
<div class="sidebar">Sidebar</div>
<div class="content">Content</div>
</div>CSS:
.header {
width: 100%;
background-color: green;
}
.container {
display: flex;
flex-wrap: wrap-reverse;
}
.content {
width: 300px; /* Specify minimum content width */
background-color: red;
height: 100px;
flex-grow: 1;
}
.sidebar {
background: blue;
width: 240px;
height: 100px;
}这里有一些关于柔性盒设计的信息。http://css-tricks.com/snippets/css/a-guide-to-flexbox/
https://stackoverflow.com/questions/26276273
复制相似问题