[英]Change width of div without affecting contents inside
我想創建一組svg圖像並將其放置在div中。 當該div調整大小(在javascript中)時,我希望更改寬度,而不更改其內部內容,從而提供調整后的div覆蓋內容的效果(例如,將div的寬度減半將使隱藏的內容一半)。
是否可以通過html?
這是一個js小提琴 。 當您按下按鈕時,div寬度將更改為較小的尺寸。 我希望它隱藏svg的一部分。
<div id="container">
<svg width="400" height="280">
<rect x="50" y="20" rx="20" ry="20" width="150" height="150" style="fill:red;stroke:black;stroke-width:5;opacity:0.5"></rect>
<rect x="90" y="50" rx="20" ry="20" width="150" height="150" style="fill:blue;stroke:black;stroke-width:5;opacity:0.5"></rect>
</svg>
</div>
將overflow:hidden或overflow:scroll添加到您的CSS
#container{
width:50%;
background-color:red;
Overflow:hidden;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.