页面HTML
<div class="outbox">
<p class="heading">Header-1 </p>
<div class="content">Lorem ipsum dolor sit amet</div>
<p class="heading">Header-2</p>
<div class="content">Lorem ipsum dolor sit amet</div>
<p class="heading">Header-3</p>
<div class="content">Lorem ipsum dolor sit amet</div>
</div>
CSS
.outbox
{
margin: 0;
padding: 0;
}
.heading
{
background-color: #FF6666;
border: 1px solid #FF5050;
text-align: center;
font-weight: bold;
margin: 1px;
padding: 3px 10px;
cursor: pointer;
float: right;
width: 300px;
height:25px;
}
.content
{
background-color: #FFCCCC;
}
JQUERY
<script type="text/javascript">
$(document).ready(function() {
$(".content").hide();
$(".heading").click(function()
{
$(this).next(".content").slideToggle(500);
});
});
</script>
当我点击内容的任何标题时,展开的部分始终显示在页面顶部。如何在标题下方显示?提前谢谢。
答案 0 :(得分:1)
从标题中删除float: right;
样式。除非它是故意的,但在那种情况下你的问题听起来很奇怪。
答案 1 :(得分:1)
答案 2 :(得分:1)
试试这个:
<强> HTML 强>
<div class="outbox">
<div class="container">
<p class="heading">Header-1 </p>
<div class="content">Lorem ipsum dolor sit amet</div>
</div>
<div class="container">
<p class="heading">Header-2</p>
<div class="content">Lorem ipsum dolor sit amet</div>
</div>
<div class="container">
<p class="heading">Header-3</p>
<div class="content">Lorem ipsum dolor sit amet</div>
</div>
</div>
<强> CSS 强>
.outbox
{
margin: 0;
padding: 0;
}
.heading
{
background-color: #FF6666;
border: 1px solid #FF5050;
text-align: center;
font-weight: bold;
margin: 1px;
padding: 3px 10px;
cursor: pointer;
width: 300px;
height:25px;
}
.container{
float:right;
}
.content
{
background-color: #FFCCCC;
}
答案 3 :(得分:0)
向您的.content
课程展开,并将clear:both
添加到您的.heading
和.content
,然后尝试以下方法:
.heading {
clear: both;
background-color: #FF6666;
border: 1px solid #FF5050;
text-align: center;
font-weight: bold;
margin: 1px;
padding: 3px 10px;
cursor: pointer;
float: right;
width: 300px;
height:25px;
}
.content {
clear: both;
float: right;
background-color: #FFCCCC;
}
What is the use of style=“clear:both”?
查看JSFiddle