简体   繁体   English

如何创建在鼠标悬停时扩展更多信息的div(带有背景图片?

[英]How do I create a div that expands with more information upon mouseover (with a background image?

I would like to create a div that expands to two paragraphs when someone mouses over the first paragraph. 我想创建一个div,当有人将鼠标悬停在第一段上时,它会扩展为两个段。 The first paragraph would be an introduction. 第一段是引言。 The second paragraph would explain a bit more and may contain a link to another page. 第二段将说明更多内容,并可能包含指向另一页的链接。 I would like the second paragraph to be hidden until the person moused over the introductory paragraph. 我希望隐藏第二段,直到该人将鼠标悬停在介绍段上。 I have a background image which looks like a Post-it note. 我有一张看起来像便利贴的背景图片。

My attempts at this are here: http://jsfiddle.net/sAW2c/52/ . 我在这里的尝试是: http : //jsfiddle.net/sAW2c/52/ The second paragraph isn't hidden, even though I constrained the size of the div and the padding on the P isn't working either. 即使我限制了div的大小并且P上的填充也不起作用,第二段也没有隐藏。 Can someone head me in the correct direction? 有人可以指引我正确的方向吗?

Adding overflow: hidden; 添加overflow: hidden; to your #div1 seems to fix the issue: little link . 您的#div1似乎可以解决此问题: 小链接

Note: Please use jsFiddle's CSS tab for styles next time. 注意:下次请使用jsFiddle的CSS标签来设置样式。 Inline styles are generically not very preferable. 通常,内联样式不是很可取。

Adding overflow hidden to the div should help. 将隐藏的溢出添加到div应该会有所帮助。 Check out this jsFiddle example . 看看这个jsFiddle示例 You should get the basic idea here but you'll need to tweak your background and text padding. 您应该在这里得到基本的想法,但是您需要调整背景和文本填充。

jQuery jQuery的

$("#div1").hover(function() {
    $(this).animate({
        height: '300px'
    });
}, function() {
    $(this).animate({
        height: '100px'
    });
});​

HTML HTML

<div id="div1" style="height:120px; width:206px;overflow:hidden;background: url('http://quiltersbee.com/images/white-postit.png') no-repeat 0 0; ">
    <p style="padding-left: 8;padding-right: 8;">This is the paragraph that I would like to be only 190px wide and placed on the background image.  It should be left-aligned. </p><br />
    <p style="padding-left: 8;padding-right: 8;">This is the paragraph I would like to hide until someone mousesovers the above paragraph.  Both paragraphs should be indented so they don't overlap the shading on the background image when this paragraph shows.  This paragraph may include a link.</p>
</div>​

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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