看看下面的JSFiddle圖像與背景圖像不顯示
.container {
\t width: 100%;
\t background-color: yellow;
}
.classic {
\t display: block;
\t position: relative;
\t margin-left: auto;
\t margin-right: auto;
\t background-position: center center;
\t background-image: url("http://www.pulsarwallpapers.com/data/media/3/Alien%20Ink%202560X1600%20Abstract%20Background.jpg");
\t background-size: contain;
\t background-repeat: no-repeat;
}
.classic-img {
\t display: block;
\t position: absolute;
\t overflow: hidden;
\t width: 100%;
\t height: 100%;
\t top: 0%;
\t left: 0%;
}
.classic-img img {
\t position: absolute;
\t width: 100%;
\t height: 100%;
\t top: 0;
\t left: 0;
}
.top-menu {
\t width: 100%;
\t height: 50px;
\t position: relative;
\t background-color: red;
}
.top-menu-buttons {
\t position: absolute;
\t margin-left: auto;
\t margin-right: auto;
\t bottom: 0;
\t left: 0;
\t right: 0;
\t width: 50%;
\t text-align: center;
}
.top-menu-buttons .button {
\t display: inline-block;
\t vertical-align: middle;
\t font-size: 25px;
\t color: white;
}
.top-menu-buttons span {
\t display: inline-block;
\t vertical-align: middle;
\t font-size: 25px;
\t color: white;
}
.bottom-menu {
\t width: 100%;
\t height: 50px;
\t position: relative;
\t background-color: green;
}
.bottom-menu-buttons {
\t position: absolute;
\t margin-left: auto;
\t margin-right: auto;
\t bottom: 0;
\t left: 0;
\t right: 0;
\t width: 80%;
\t text-align: center;
}
.bottom-menu-buttons .button {
\t display: inline-block;
\t vertical-align: middle;
\t font-size: 35px;
\t color: white;
\t padding-left: 10px;
\t padding-right: 10px;
} \t
<div class="list">
\t <a class="item">
\t \t <div id="container" class="container">
\t \t \t <div class="top-menu">
\t \t \t \t <div class="top-menu-buttons">
\t \t \t \t \t <button>-</button>
\t \t \t \t \t <span>20</span>
\t \t \t \t \t <button>+</button>
\t \t \t \t </div>
\t \t </div>
\t \t <div id="classic" class="classic">
\t \t \t <div id="classic-img" class="classic-img">
\t \t \t \t <img src="http://bc03.rp-online.de/polopoly_fs/1.4643662.1415087612!httpImage/2100575733.JPG_gen/derivatives/d540x303/2100575733.JPG" />
\t \t \t </div>
\t \t </div>
\t \t \t
\t \t <div class="bottom-menu">
\t \t \t <div class="bottom-menu-buttons">
\t \t \t <button class="button button-icon ion-eye">1</button>
\t \t \t <button class="button button-icon ion-refresh">2</button>
\t \t \t <button class="button button-icon ion-crop">3</button>
\t \t \t <button class="button button-icon ion-android-options">4</button>
\t \t \t <button class="button button-icon ion-social-tumblr">5</button>
\t \t </div>
\t </div>
\t </a>
</div>
CSS:
我想要實現的是類似以下內容:
紅色區域應該是頂層菜單。它不應該是一個固定的頂級位置,它應該始終位於圖像的頂部。
正如你所看到的圖像有白色的背景和黑色的背景。它應該看起來像一個寶麗來。
綠色區域應該是底部的菜單,但也不是固定在底部,它應該總是在圖像下面。如果沒有足夠的空間,它應該簡單地滾動而不是抓住任何div。我猜主要的問題是在背景圖像與圖像中間的div。
我嘗試了很多年,現在得到正確的CSS,但不幸的是,我很無經驗,我現在可以做的是嘗試和錯誤,但我無法得到它的工作。
嗯...那不會導致我想要達到的結果。圖像半身像與背景圖像一起在div的內部。你js小提琴顯示圖像比背景圖像大。 – Mulgard
你的圖片應該比背景圖片小? –
yes ofcourse。就像我在開幕文章中展示的例子。圖像的白色區域是背景圖像。黑色區域是裏面的圖像。 – Mulgard