我正在使用手风琴来制作一些过滤器并在其下方放置一些文字。我希望手风琴将文本叠加为一层。在下面的代码中,手风琴将文本向下推。
我尝试使用z-index,但似乎没有用。关于什么是错的任何帮助/想法?
非常感谢! 维拉
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
* {
margin: 0;
padding: 0;
font-family: 'Arial', sans-serif;
}
.accordion-container {
width: 20%;
float:left;
margin-right: 3px;
}
.accordion-toggle {
display: block;
padding: 13px 10px 10px 10px;
font-size: 1em;
font-weight: 400;
background: #535860;
color: #fff;
text-decoration: none;
vertical-align: middle;
letter-spacing: 0.1em;
}
.accordion-toggle.open {
background: #E84A2B;
color: #fff;
}
.accordion-toggle:hover {
background: #E84A2B;
}
.accordion-toggle span.toggle-icon {
position: absolute;
top: 9px;
right: 12px;
font-size: 1.5em;
font-weight: 400;
}
.accordion-content {
margin-top: 3px;
display: none;
overflow: auto;
background-color: #535860;
-webkit-box-shadow: 0px 10px 10px -5px rgba(0,0,0,0.2);
-moz-box-shadow: 0px 10px 10px -5px rgba(0,0,0,0.2);
box-shadow: 0px 10px 10px -5px rgba(0,0,0,0.2);
}
.accordion-content img {
display: block;
float: left;
margin: 0 15px 10px 0;
max-width: 100%;
height: auto;
}
/* media query for mobile */
@media (max-width: 960px) {
.accordion-container {
width: 100%;
float:left;
position:relative;
}
.content {
float: left;
width: 100%;
}
.accordion-content {
padding: 10px 0;
overflow: auto;
}
}
</style>
</head>
<body>
<div class = "main" style = "position:relative; z-index: 999;">
<div class="accordion-container">
<a href="#" class="accordion-toggle">ROME<span class="toggle-icon">
<!--<i class="fa fa-caret-down"></i>-->+
</span></a>
<div class="accordion-content l1">
<img src="images/italy-thumb_rome.jpg" />
<p>Test</p>
</div>
</div>
<div class="accordion-container">
<a href="#" class="accordion-toggle">ROME<span class="toggle-icon">+</span></a>
<div class="accordion-content">
<img src="images/italy-thumb_rome.jpg" />
<p>Test</p>
</div>
</div>
<div class="accordion-container">
<a href="#" class="accordion-toggle">ROME<span class="toggle-icon">+</span></a>
<div class="accordion-content">
<img src="images/italy-thumb_rome.jpg" />
<p>Test</p>
</div>
</div>
<div class="accordion-container">
<a href="#" class="accordion-toggle">ROME<span class="toggle-icon">+</span></a>
<div class="accordion-content">
<img src="images/italy-thumb_rome.jpg" />
<p>Test</p>
</div>
</div>
<p style = "position:relative; z-index: -999;">Random Text Area unit</p>
</div>
<!-------------------- JS -------------------->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$('.accordion-toggle').on('click', function(event){
event.preventDefault();
// create accordion variables
var accordion = $(this);
var accordionContent = accordion.next('.accordion-content');
var accordionToggleIcon = $(this).children('.toggle-icon');
// toggle accordion link open class
accordion.toggleClass("open");
// toggle accordion content
accordionContent.slideToggle(90);
// change plus/minus icon
if (accordion.hasClass("open")) {
accordionToggleIcon.html("–");
} else {
accordionToggleIcon.html("+");
}
});
});
</script>
</body>
</html>
答案 0 :(得分:0)
位置relative
的元素仍然处于正常流程中,因此在上面添加新内容时会将其向下推。如果您想要覆盖某些内容,则应使用position:absolute
或position:fixed