2015-03-08 92 views
0

我想在網頁中心放置一個固定的圖像,我想要剩餘的空間充滿背景或不透明度,但兩者都不起作用。全屏幕背景圖像周圍的空白空間

.imagecontainer 
 
{ 
 
    
 
    float: left; 
 
overflow: auto; 
 
    width: 100%; 
 
    height: 100%; 
 
    background: black; 
 
} 
 
.imagepop { 
 
    
 
    background: black; 
 
    max-width: 100%; 
 
    max-height: 100%; 
 
    bottom: 0; 
 
    left: 0; 
 
    margin: auto; 
 
    overflow: auto; 
 
    position: fixed; 
 
    right: 0; 
 
    top: 0; 
 
} 
 

 
#topright { 
 
    background: silver; 
 
    text-decoration: none; 
 
    border: 1px solid black; 
 
    position: absolute; 
 
    right: 0; 
 
    top: 20; 
 
    display: block; 
 
    
 
}
<div class="imagecontainer"><img id="image" src="http://img.cricinfo.com/espncricinfo/Img_nav-div-background.gif" class="imagepop" /> 
 
    <a id="topright" href="#" title="TopRight">Close</a></div>

回答

0

它的工作,但你的imagecontianer是0像素的高度。 添加

position: absolute 

你的形象conainer

或easies方式:

.imagecontainer 
{ 
    position:absolute; 
    left:0; 
    top:0; 
    right:0; 
    bottom:0; 
    background: black; 
} 
+0

爲什麼會出現不必要的保證金,如果我加入嗎? – Vishnu 2015-03-08 17:27:56

+0

@Vishnu可能(瀏覽器)默認保證金。不確定,但將'margin:0;'添加到'body'可能會解決這個問題。 – Tedil 2015-03-08 17:51:27