gpt4 book ai didi

javascript - Onclick 文本出现在 div 旁边,而不是在下面

转载 作者:行者123 更新时间:2023-12-01 02:39:25 25 4
gpt4 key购买 nike

我的代码有问题,我希望 onclick 中显示的文本位于主 div 下方,但它却出现在主 div 旁边。有人可以知道我犯的错误或者我可以添加到我的代码中来纠正这个错误吗?我还有另一个问题,如何在 div 之间添加空间,因为我放置了蓝色背景,但我不想像一个 block 一样。谢谢

<style type="text/css">
.link{text-decoration:none; color:white;}

.link:visited{color:white}

.row {
display: flex; /* equal height of the children */
}

.col {
flex: 1; /* additionally, equal width */

padding: 1em;
border: solid;
}

div {font-family:'Varela Round';
}

.opener {
background-color: #07183d;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
}

.benefits {
background-color: #07183d;
border: none;
color: white;
padding: 15px 32px;
text-decoration: none;
display: inline-block;
font-size: 16px;
width:300px;
}
</style>
<style type="text/css">}
a {
text-decoration: none;
}
a:visited {
text-decoration: none;
color: white;
}
#upbutton {
border: 1px dotted white;
}
</style>
<script>function show(id) {
if(document.getElementById('b'+id).style.display=='none') {
document.getElementById('b'+id).style.display='block';
}
return false;
}
function hide(id) {
if(document.getElementById('b'+id).style.display=='block') {
document.getElementById('b'+id).style.display='none';
}
return false;
}
</script>
<div class="row">
<div class="opener col"><a href="#1" name="1" onclick=" show('1');" class="link">SOCIETES: 400</a></div>

<div class="benefits" id="b1" style="display:none;">Part SBF 120 : 120<br />
Part Filiales +100M€: 280
<div id="upbutton"><a onclick=" hide('1');" >fermer</a></div>
</div>

<div class="opener col"><a href="#1" name="1" onclick=" show('2');" class="link" >CONTACTS: 25 400</a></div>

<div class="benefits col" id="b2" style="display:none;">Part CAC 40 : 15 700<br />
Part Filiales +100M€: 9 700<br />
% contacts IT: 21%
<div id="upbutton"><a onclick=" hide('2');">fermer</a></div>
</div>

<div class="opener col">EMAILS NOMINATIFS: 400</div>

<div class="opener col">OPT OUT: 3%</div>

<div class="opener col">LIGNES DIRECTES: 35%</div></div>

最佳答案

只需将隐藏的 div 添加到 opener div 旁边,它将出现在其下方,要在 div 之间添加空间,您可以使用 opener div 的 border 属性,请尝试以下代码:

<style type="text/css">
.link{text-decoration:none; color:white;}

.link:visited{color:white}

.row {
display: flex; /* equal height of the children */
}

.col {
flex: 1; /* additionally, equal width */

padding: 1em;
border: solid;
}

div {font-family:'Varela Round';
}

.opener {
background-color: #07183d;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
border: 1px white solid;
}

.benefits {
background-color: #07183d;
border: none;
color: white;
padding: 15px 32px;
text-decoration: none;
display: inline-block;
font-size: 16px;
width:300px;
}
</style>
<style type="text/css">}
a {
text-decoration: none;
}
a:visited {
text-decoration: none;
color: white;
}
#upbutton {
border: 1px dotted white;
}
</style>
<script>function show(id) {
if(document.getElementById('b'+id).style.display=='none') {
document.getElementById('b'+id).style.display='block';
}
return false;
}
function hide(id) {
if(document.getElementById('b'+id).style.display=='block') {
document.getElementById('b'+id).style.display='none';
}
return false;
}
</script>
<div class="row">
<div class="opener col"><a href="#1" name="1" onclick=" show('1');" class="link">SOCIETES: 400</a>

<div class="benefits" id="b1" style="display:none;">Part SBF 120 : 120<br />
Part Filiales +100M€: 280
<div id="upbutton"><a onclick=" hide('1');" >fermer</a></div>
</div>
</div>

<div class="opener col"><a href="#1" name="1" onclick=" show('2');" class="link" >CONTACTS: 25 400</a>

<div class="benefits col" id="b2" style="display:none;">Part CAC 40 : 15 700<br />
Part Filiales +100M€: 9 700<br />
% contacts IT: 21%
<div id="upbutton"><a onclick=" hide('2');">fermer</a></div>
</div>
</div>
<div class="opener col">EMAILS NOMINATIFS: 400</div>

<div class="opener col">OPT OUT: 3%</div>

<div class="opener col">LIGNES DIRECTES: 35%</div></div>

关于javascript - Onclick 文本出现在 div 旁边,而不是在下面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47670862/

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