2014-03-26 43 views
1

是否有可能定義位置(中心),在這種情況下,圖像div,在div溢出?定義位置內容Div溢出滾動

http://jsfiddle.net/KAy22/1/

#scroll-h-v { 
    width: 300px; 
    height: 300px; 
    position: relative; 
    overflow: auto; 
} 
.image { 
    text-align: center; 
    margin-left: auto; 
    margin-right: auto; 
    position: relative; 
} 

圖像應在中央這樣​​的負荷:

center image

回答

1

您可以用頂部和左側位置和margin屬性發揮如下

.image { 
    text-align: center; 
    margin-left: auto; 
    margin-right: auto; 
    position: relative; 
    top:50%; 
    left:50%; 
    margin-top:-500px; 
    margin-left:-500px; 
} 

http://jsfiddle.net/KAy22/2/

希望它有幫助!

+0

是的,正確的方法。但是有可能看到整個圖像嗎? – l00per

+0

你想縮放這樣的圖像嗎?http://jsfiddle.net/KAy22/3/ tp佔用容器的寬度 –

+0

其實像這樣:http://jsfiddle.net/KAy22/1/。但我想展示部分,但想滾動整個圖像。因此,圖像應設置爲頂部:-300像素,左側:-300像素,但不切割圖像。 – l00per