gpt4 book ai didi

javascript - HTML:如何在页面展开前后将按钮定位在页面底部

转载 作者:行者123 更新时间:2023-11-28 16:53:11 24 4
gpt4 key购买 nike

我试图将提交按钮放置在具有可扩展表格的页面底部。

如果我使用 position: absolute然后我可以在表格未展开时将其放在底部但是当我展开表格时,表格数据位于提交按钮下方,因为它不会随着表格展开而移动(由于使用绝对)。

如果我使用 position: relative那么当表格未展开时提交按钮将不会在页面底部(由于使用相对)。

在上述两种情况下,有什么办法可以让提交按钮位于页面底部吗?我试过放置 <input type="submit" value="Submit" id="button1" />在我拥有的每个 div 中,也将 div 排除在外。我需要将屏幕分成两个垂直部分的两个 div。

jsfiddle 演示位于 submit button at bottom示例代码如下:

<html>
<head>
<title>CommDesk Dashboard</title>
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".btn1").click(function(){
$(".expand1").toggle();
});
$(".btn2").click(function(){
$(".expand2").toggle();
});
})
</script>
<style>
.expand1 { display: none;
}
.expand2 { display: none;
}

body {
background-color: AliceBlue;
}
span.note1 {float:left}
span.note2 {font-size:80%}

table#t02, #t02 th, #t02 td {
border: none;
border-collapse: collapse;
font-size:80%;
}
#button1{
position: absolute;
bottom:10px;
left:50%;
}
</style>
</head>
<body>
<form method="post">
<div style="float:left; width:50%; background-color: red">

<table id="t02" class="table2">
<tr>
<th></th>
<th></th>
<th style="color:green">Green</th>
<th style="color:gold", colspan="3">Yellow</th>
<th></th>
<th style="color:red">Red</th>
</tr>
<tr>
<td class="btn1">Post-IVR Call Volume</td>
<td>&lt</td>
<td><input type="text", name="post_ivr_call_volume_good_high", size="2", maxlength="3"></td>
<td><input type="text", name="post_ivr_call_volume_warning_low", size="2", maxlength="3"></td>
<td>to</td>
<td><input type="text", name="post_ivr_call_volume_warning_high", size="2", maxlength="3"></td>
<td>&gt</td>
<td><input type="text", name="post_ivr_call_volume_critical_low", size="2", maxlength="3"></td>
</tr>
<tr>
<td align="center" class="expand1" colspan="8">States</td></tr><tr>
</tr>
<tr>
<td class="btn2">IVR Call Volume</td>
<td>&lt</td>
<td><input type="text", name="ivr_call_volume_good_high", size="2", maxlength="3"></td>
<td><input type="text", name="ivr_call_volume_warning_low", size="2", maxlength="3"></td>
<td>to</td>
<td><input type="text", name="ivr_call_volume_warning_high", size="2", maxlength="3"></td>
<td>&gt</td>
<td><input type="text", name="ivr_call_volume_critical_low", size="2", maxlength="3"></td>
</tr>
<tr>
<td align="center" class="expand2" colspan="8">States</td></tr><tr>
</tr>
</table>
</div>
<input type="submit" value="Submit" id="button1" />
<div style="float:left; width:50%; background-color: yellow">Place Holder</div>
</form>
</body>
</html>

最佳答案

不确定纯 CSS 解决方案,但这是部分 jQuery/部分 CSS 解决方案:

1) 我已将您的左侧 block 显示更改为内联 block ,并删除了 float ,因此当 block 可见时可以向下推按钮元素...

2) 和 jquery 改变位置:

$(document).ready(function() {
$(".btn1").click(function() {

$(".expand1").toggle();
if ($('.expand1').is(':visible')) {

$('#button1').css('position', 'relative');

} else {
$('#button1').css('position', 'absolute');
}


});
$(".btn2").click(function() {
$(".expand2").toggle();

if ($('.expand2').is(':visible')) {

$('#button1').css('position', 'relative');

} else {
$('#button1').css('position', 'absolute');
}

});

});

演示:http://jsfiddle.net/poj70m4u/

关于javascript - HTML:如何在页面展开前后将按钮定位在页面底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32510958/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com