简体   繁体   中英

How can I create a div which doesn't resize itself when the inner content changes?

I'm trying to create a media feed, which may contain text, images, videos, etc. Some of these posts may be explicit, so I want to hide the content of the post with a warning, which the user would have to click to see the post.

I've successfully done this, except the div containing he post changes size when the warning is clicked. How can I change this so that the size of the div remains constant when the inner content changes?

You can use below code which does not resize div. It will allow to scroll content within fixed size.

eg.

<div class="text-center" style="height: 300px; overflow-y: auto;">
//contents inside div
</div>

You need to set div style to:

height: 100px; // or max-height with any other value
overflow: scroll; // for scrolling content if it's height greater than div's height

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM