我有这个布局,我试图在不移动options
div的情况下打开buttons
div。知道怎么做吗?
JSFiddle link
$(document).ready(function() {
$("#btn1").click(function() {
$("#options1").toggle();
});
$("#btn2").click(function() {
$("#options2").toggle();
});
$("#btn3").click(function() {
$("#options3").toggle();
});
});
.btn {
width: 100px;
background-color: black;
color: white;
height: 30px;
display: inline-block;
}
.cont {
display: inline-block;
}
.options {
width: 200px;
height: 150px;
background: green;
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="cont">
<div id="btn1" class="btn">button 1</div>
<div id="options1" class="options"></div>
</div>
<div class="cont">
<div id="btn2" class="btn">button 2</div>
<div id="options2" class="options"></div>
</div>
<div class="cont">
<div id="btn3" class="btn">button 3</div>
<div id="options3" class="options"></div>
</div>
最佳答案
很简单,将position: absolute
添加到options类
.options{
position:absolute;
width: 200px;
height: 150px;
background: green;
display: none;
}
关于javascript - 如何在不更改其他div位置的情况下动态打开div,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39739960/