我已經設置html和身體寬度和高度爲100%。爲什麼這不足以讓我的背景圖像顯示(#home1,#home2,#home3)?這不是設置所有div將基於其高度的像素嗎?我想讓內容指定頁腳和頁眉的高度,即沒有像素高度。佈局應該是:logo ...全高(減去頁眉和頁腳)。 #photo-group ...全高(減去頁眉和頁腳)。類.pic-group應使每張照片的#photo-group的30%。目前,除非我在.pic-group類上創建像素高度,否則不顯示圖像。我想做什麼,我錯過了一些明顯的東西?設置基於像素的高度將'侮辱'我的嘗試流暢的佈局。瞭解基於百分比的div和響應式設計
<?php
session_start();
include('debug-code.php');
$thisPage = "home";
$title="";
$metaDesc="";
include('head.php');?>
<style>
html {
height:100%;
font-size: 100%;
overflow-y: scroll;
}
body {
font-size:16px;
color:#434c50;
font-family: arial, serif;
background:white;
width:100%;
height:100%;
}
.clearfix:after {
content: " "; /* Older browser do not support empty content */
visibility: hidden;
display: block;
clear: both;
height:0;
}
#home-container {
position:relative;
margin:0 auto;
width:70%;
background:white;
}
#home-content {
position:relative;
}
#home-content .content {
width:100%;
}
div.logo.home {
position:relative;
float:left;
width:60%;
background:#fdf2fd;
}
div.logo.home img {
width:60%;
}
#home-footer {
position:relative;
bottom:0;
background:#d5d0d5;/*url('../images/footerBG.png')*/;
color:white;
border-top:1px solid #05577a;
}
#home-footer .content {
margin:0 auto;
width:70%;
padding:1.5rem 0;
}
#photo-group {
display:block;
width:20%;
height:100%;
float:left;
}
.pic-group {
height:30%;
display:block;
position:relative;
}
#home1 {
background: blue url('../images/home1.png') no-repeat top left;
background-size:100%;
}
#home2 {
background:yellow url('../images/home2.png') no-repeat top left;
background-size:100%;
}
#home3 {
background:red url('../images/home3.png') no-repeat top left;
background-size:100%;
}
</style>
</head>
<body>
<?php include('home-header.php')?>
<div id="home-container"><div class="content clearfix">
<div id="home-content"><div class="content clearfix">
<div class="logo home"><?php include('logo-home-image.htm');?></div>
<div id="photo-group">
<div id="home1" class="pic-group"></div><div id="home2" class="pic-group"></div><div id="home3" class="pic-group"></div>
</div>
<?php include('home-menu.php');?>
<div id='mobile-menu'></div>
</div></div><!--end content-->
<?php include("disclaimer.htm") ?>
</div></div><!--end container-->
<?php include("home-footer.htm") ?>
</body>
</html>
您的回覆以多種方式幫助我。我已經在html中包含了我需要的圖像,而不是作爲背景圖像。我是否正確地從您的答案中推斷出背景圖像不能被使用,除非高度被明確地設置在div鏈的某處?如果是這樣,那麼如何保持響應式設計的流體佈局(%)? Java的? – Leslie 2015-01-10 18:25:12
@萊斯利設置背景不會觸發高度。將它與現實生活進行比較。如果您將海報放入小照片列表中,則只會顯示海報的一部分,因爲尺寸不匹配。流體設計不是一個問題與CSS。你只需要設置正確的offsetparent與高度。如果你給'#家容器'高度'100%'它應該給你結果。 – Mouser 2015-01-10 18:46:09
謝謝你的解釋。 – Leslie 2015-01-11 18:24:17