CSS - jQuery 隐藏/显示 div 改变高度
这可能是一个菜鸟问题,但我想隐藏 P 标签 (.feedback-text) 中的内容,而不改变 div (.feedback-box) 的高度。
<div class="feedback-box">
<p class="feedback-text"></p>
</div>
p 标签内会有不同长度的文本,但我不希望 div 随其上下滑动。 div 必须保持相同的大小,除非文本比以前更大或更小。
文本发生变化的原因是 ajax 从数据库获取不同的反馈条目。请参阅此问题了解更多信息。
我希望我已经说清楚了。谢谢。
编辑:
请参阅此网站,我正在其中进行测试。正如您所看到的,当 p 标签隐藏并再次显示时,反馈框 div 会跳跃。
This may be a noob question but I want to hide the content within the P tag (.feedback-text), without the height of the div (.feedback-box) changing.
<div class="feedback-box">
<p class="feedback-text"></p>
</div>
The p tag will have different lengths of text within it, but I do not want the div it from sliding up/down with it. The div must stay the same size unless the text it larger or smaller than before.
The reason why the text is changing is because ajax is getting different feedback entrys from a database. See this question for more information.
I hope I have made this clear. Thanks.
EDIT:
Please see this website, where I'm doing my tests. As you can see the feedback-box div is jumping around when the p tag is hidden and shown again.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需设置
不透明度
的动画即可。这使得该元素不可见,但仍然存在:您的 JS 代码似乎有点可疑。尝试用这个替换它:
Just animate the
opacity
. This makes the element invisible, but still there:Your JS code seems a bit fishy. Try replacing it with this:
您可以设置 css 属性:
这是您想要的吗?
You could set the css property:
Is this what you want?
正如我所看到的(并且理解它,我不确定我是否理解),您有三个选择:
overflow-y:auto
如果太大则滚动。visibility:hidden;
As I see it (and understand it, which I'm not sure I do), you have three options:
overflow-y:auto
to scroll if it gets too big.visibility:hidden;
on the child