动态div内容,但需要固定div高度
我正在使用 javascript 来制作 div 折叠/滑动的动画。 javascript 要求 div 有一个设定的高度,尽管 div 内的内容是动态的。我将如何使其工作,因为我不希望 div 比它的预期更大。我已经像这样设置了 div 的高度:
<div id="main-div" style="overflow:hidden; height:95px;">
我尝试将高度设置为“自动”,但是当 div 再次滑动打开时,它不会滑动到正确的高度。我需要计算高度吗?
I'm using javascript to animate a div collapsing/sliding. The javascript requires the div to have a set height, although the content inside the div is dynamic. How would I go about making it work, as I don't want the div to be any larger than it's meant to. I've set the height of the div like this:
<div id="main-div" style="overflow:hidden; height:95px;">
I've tried setting the height to 'auto' but when the div slides open again, it doesn't slide to the correct height. Would I need to calculate the height?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不需要“自动”,因为这意味着“使框高度适合内容高度”。你是说设置height属性不起作用?你的完整 div 标记是什么?
You don't want 'auto' as that means "fit the box height to the content height." Are you saying that setting the height attribute is not working? What is your full div markup?
尝试设置
min-height
和max-height
。我不确定我是否理解你的问题。您当前的方法有问题吗?那是什么问题?
Try setting
min-height
andmax-height
as well.And I'm not sure I understand your question. Do you have a problem with your current approach? What is that problem?