当我单击名为“ test”的div时,也会出现一个名为“ outside”的div,其z-index值较高的一个div名为“ inside”。
我的问题是,当我将位置的绝对值设置为“内部”时,我无法将页边距设置为底。当我将位置设置为相对时,会将div“测试”置于其下方。
理解起来可能有些困难,但是问题确实很简单。这里是一个小提琴:http://jsfiddle.net/malamine_kebe/QRpqs/
我的CSS是:
#insideAbsolute{
background-color:#f8f8f8;
position: absolute;
top:0;
left:20%;
width:60%;
margin-top:35px;
margin-bottom:35px;
z-index:3;
border-radius: 7px;
box-shadow: 6px 6px 20px black;
}
#insideRelative{
background-color:#f8f8f8;
position: relative;
top:0;
left:20%;
width:60%;
margin-top:35px;
margin-bottom:35px;
z-index:3;
border-radius: 7px;
box-shadow: 6px 6px 20px black;
}
#outside{
position: fixed;
left:0;
top:0;
height: 100%;
width: 100%;
background-color: black;
opacity:0.7;
z-index:2;
background-attachment:fixed;
}
.test{
z-index:1;
}
我的HTML:
<div id="outside"></div>
<div id="insideAbsolute"></div>
<div id="insideRelative"></div>
<div class="testAbsolute">test position absolute</div>
<div class="testRelative">test position relative</div>
和我的jQuery
$('#outside').hide();
$('#insideAbsolute').hide();
$('#insideRelative').hide();
$(document).on('click', '.testAbsolute', function () {
$('#outside').show(0, function() {
$('#insideAbsolute').show(0, function() {
$(this).html('<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>');
$(document).on('click','#outside',function(){
$('#insideAbsolute').html('');
$('#outside').hide();
});
});
});
});
$(document).on('click', '.testRelative', function () {
$('#outside').show(0, function() {
$('#insideRelative').show(0, function() {
$(this).html('<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>');
$(document).on('click','#outside',function(){
$('#insideRelative').html('');
$('#outside').hide();
});
});
});
});
最佳答案
这里给你一个小把戏。将此添加到您的CSS中:
#insideAbsolute:after{
content:'';
height : 35px;
width : 100%;
position : absolute;
bottom : -35px;
}
那创造了“假”的保证金!
小提琴:http://jsfiddle.net/QRpqs/1/