2016-11-30 74 views
0

我有兩個div div div的孩子是在div的父母。 div小孩比他的父母大。所以我決定在div div中添加一個滾動條,因爲我可以更好地看到div子的內容。剪輯div也剪輯滾動

問題是,現在我需要使用父級div中的屬性剪輯,但剪輯也會影響滾動。

我想問的是,如果有任何方法可以將父div和滾動大小ajdustes automaclty剪貼到滾動條上。

跟隨我的代碼:

.outter{ 
 
    width:100px; 
 
    height:100px; 
 
    background-color:blue; 
 
    overflow: scroll; 
 
    position: absolute; 
 
    clip: rect(23.75px 120px 120px 23.75px); 
 
} 
 

 
.inner{ 
 
    width:200px; 
 
    height:200px; 
 
    background-color:red; 
 
    
 
}
<div class="outter"> 
 
    <div class="inner"></div> 
 
</div>

[編輯]:

跟隨你,結果我假裝。

enter image description here

如果你比比上面的圖片,並且我把上面的代碼片段的結果是,在結果中滾動apears切斷,圖像不

+1

通常我們叫它子和父DIV ...不是兒子和父親 – k97513

+0

謝謝@ k97513。我已經做了改變:) –

+0

我不明白你想要什麼結果。可以發佈你想要實現的圖像嗎? –

回答

0

這是clip屬性是什麼應該這樣做,限制元素的可見區域。如果你試圖剪輯內部元素的內容,你可以絕對定位它。

希望這會有所幫助!

.outter { 
 
    position: relative; 
 
    width:160px; 
 
    height:160px; 
 
    background-color:red; 
 
    overflow: scroll; 
 
} 
 

 
.inner{ 
 
    position: absolute; 
 
    left: -40px; 
 
    top: -40px; 
 
    background:url('http://placekitten.com/g/400/400'); 
 
    background-size: cover; 
 
    background-repeat: no-repeat; 
 
    background-position: center; 
 
    width:400px; 
 
    height:400px; 
 
}
<div class="outter"> 
 
    <div class="inner"> 
 
    </div> 
 
</div>

+0

我正在一個大的web應用程序。部分代碼已經實現,我無法按照自己想要的方式更改。你給我的解決方案我已經有了,但是我得出的結論是,這對我來說並不合適。但是,謝謝你試圖幫助我。 –