我需要在我的标题图片之后开始内容。它适用于静态页面,但问题是我的网站是可扩展的,所以如果有人从iPhone进入我的网站,一切都会缩小,但选项TOP仍将保持300px,并将在标题和内容之间产生更大的差距。 这是我的代码。 HTML
<div id="container">
<div id="header"><img src="galvena.jpg"/></div>
<div id="content">
<div class="text">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
</div>
</div>
</div>
CSS
body{font-family: 'Roboto', sans-serif;font-size:3.6vmin;margin:0}
img{max-width:100%;height:auto;margin:0;padding:0}
#container{margin:0 auto;max-width:500px;}
#header {
position:fixed;
z-index:100;
max-width: 500px;
}
#content {
top:300px;
position:relative;
z-index:200;
width:100%;
margin:0 auto;
background-color:white;
}
.text {
width:90%;
margin:0 auto;
}
答案 0 :(得分:1)
使用jQuery,我们可以轻松获取图像的高度,并将此值设置为内容div的最高值。看看这个jsfiddle。
HTML:
<div class="flex-container">
<div class="large-flex-item"></div>
<div class="flex-container-inner">
<div class="small-flex-item"></div>
<div class="small-flex-item"></div>
</div>
</div>
CSS:
html {height: 100%;}
body{font-family: 'Roboto', sans-serif;font-size:3.6vmin;margin:0; height: 100%;}
img{max-width:100%;height:auto;margin:0;padding:0}
#container{margin:0 auto;max-width:500px; height: 100%; }
#header {
position:fixed;
z-index:100;
max-width: 500px;
}
#header img {
width: 100%;
}
#content {
top:60%;
position:relative;
z-index:200;
width:100%;
margin:0 auto;
background-color:white;
height: 90%;
}
.text {
width:90%;
margin:0 auto;
}
JS:
(function($) {
$(window).load(function() {
$('#content').css('top',$('#header img').height()+'px');
});
$(window).resize(function() {
$('#content').css('top',$('#header img').height()+'px');
});
})(jQuery);