gpt4 book ai didi

javascript - 单击选项卡后立即 float 的 HTML 按钮

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

我能够让我的按钮与我的文本区域对齐(对齐到右下角),这在我单击选项卡之前看起来不错。单击选项卡后,按钮会一直向右移动。我怀疑这与我在选项卡单击时的显示选项有关。在选项卡上单击我正在显示 div inline,如下所示:

document.getElementById(sectionName).style.display = "inline";

当我再次刷新页面时,默认显示选项似乎工作正常。

我已尝试使用不同的显示选项(例如,block),但当我单击选项卡时它们仍然向右移动。

如何防止按钮在选项卡单击时移动?

index.html:

<div id="verify" class="tabcontent statusAreaDiv">
<span class="statusTextAreaLabel">Status:</span>
<textarea class="statusTextArea" readonly></textarea>
<span class="buttonForTextArea">
<button class="button" id="btn1">Verify</button>
<button class="button" id="btn2">Download</button>
</span>
</div>
...
...
<script>
function showTab(event, sectionName) {
var tabContents = document.getElementsByClassName('tabcontent');
for (var i = 0; i < tabContents.length; i++) {
tabContents[i].style.display = 'none';
console.log("The table contents is: " + tabContents[i]);
}
var tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
console.log("tablinks class is: " + tablinks[i]);
}

document.getElementById(sectionName).style.display = "inline";
event.currentTarget.className += " active";
}
</script>

CSS:

.statusAreaDiv {
min-width: 490px;
position: relative;
display: inline-block;
}

.statusTextArea{
position: relative;
width: 800px;
border: 2px solid #dddddd;
border-radius: 10px;
height: 500px;
overflow-y: scroll;
font-size:13px;
font-family:Verdana, Geneva, sans-serif;
background-color: light grey;
}

.statusAreaDiv span.statusTextAreaLabel{
padding-top: 2em;
font-family: verdana;
display: block;
text-align: left;
font-size:13px;
}

.statusAreaDiv span.buttonForTextArea{
display: block;
text-align: right;
}

.button {
padding: 5px 15px;
font-size: 15px;
cursor: pointer;
text-align: center;
text-decoration: none;
outline: none;
color: #fff;
background-color: #368DEE;
border: none;
border-radius: 8px;
box-shadow: 0 5px #999;
}

最佳答案

试试这个,正在寻找这个吗?

*{box-sizing:border-box;font-family:sans-serif;margin:0;padding:0;}
textarea,button{
display:inline-block;
margin:20px 0;
position:relative;
vertical-align:middle;
}
textarea{
left:calc(50% - 150px);
width:300px;
}
button{
left:calc(50% - 135px);
}
<textarea></textarea><button>button</button>

关于javascript - 单击选项卡后立即 float 的 HTML 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51316756/

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