【问题标题】:Responsive 2 Column Absolute Positioning响应式 2 列绝对定位
【发布时间】:2013-05-19 00:11:09
【问题描述】:

我有一个包含 2 个部分(主容器)的单页布局。每个主容器都有 100% 的高度和宽度。我希望我在第二部分中的图像类“pic”具有绝对定位,位于第二部分的底部。截至目前,它位于第一节的底部。我想我只是没有清除正确的东西。我正在使用(移动优先初始化)模板。 http://www.initializr.com

可能没有多大帮助,但这是小提琴

演示http://jsfiddle.net/jfarr07/7dWeY/

HTML

 <div class="main-container3" id="sponsorship">
        <div class="main wrapper clearfix">
            <article>
                <header class="branding">
                 OH THE POSSIBILITIES
                </header> 
            </article>
        </div> <!-- #main -->
 </div> <!-- #main-container3 -->


<div class="main-container4" id="promotion">
<div class="wrap">
<div class="jared">
    <img class="pic" src="images/jared.png" /></div>
<div class="jaredinfo"></div>

</div>
</div> <!-- #main-container4 -->

CSS

body {
height:100%;
overflow:scroll;
}
html {
height:100%;
}
article, aside, header {
display:block; 
}
}
.main-container3 {
background-image:url(../images/gopherbackground.png);
background-position:center center;
background-repeat:no-repeat;
background-size:cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
min-height:100%;

}
.main-container4 {
background-image:url(../images/graybackground.png);
background-position:center center;
background-repeat:no-repeat;
background-size:cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
min-height:100%;
}
.wrap {
width:90%;
margin:0 auto;
height:100%;
min-height:100%;
}
.jared {
background-color:#0C6;
float:left;
position:relative;
height:100%;
min-height:100%;
width:40%;
}
.jaredinfo {
background-color:#C60;
float:right;
position:relative;
height:100%;
min-height:100%;
width:60%;
}
.pic {
position:absolute;
bottom:0;
}
.branding {
font-size:44px;
color:#FFF;
font-family: source-sans-pro, sans-serif;font-weight:700;
text-align:center;
}
.wrapper {
width: 90%;
margin: 0 5%;
max-width:1000px;
}
.main {
padding: 30px 0;
}

【问题讨论】:

  • 你真的应该提供一个更好的小提琴。由于颜色和缺少背景,目前看不到任何东西。

标签: css responsive-design css-position


【解决方案1】:

我想问题可能是第二个容器实际上的height 为零。一种解决方案是设置一个固定的height

.main-container4 {
    height: 100px;
}

Here is a demo.

如果你想让它有100%的高度,你需要设置

html { height: 100%; }

也是(连同容器上的height: 100%)。 Demo.

【讨论】:

  • Linus 这正是我想要的,但高度为 100%。
  • ...所以图像将位于该部分的底部。 "jared" 和 "jaredinfo" 将是 100% 高度以匹配 main-container4 高度。
  • 嗯,我确认这一切都在小提琴中。出于某种原因,它仍在第 1 节中。所以这绝对是一个 clearfix 问题。我没有在某处清理什么。
  • 真正的问题是当您尝试在 clearfix 之后获得 100% 的高度时。
猜你喜欢
  • 1970-01-01
  • 2019-02-06
  • 2014-12-04
  • 1970-01-01
  • 2021-09-29
  • 2023-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多