gpt4 book ai didi

javascript - 如何根据内容调整 Accordion 文本大小

转载 作者:行者123 更新时间:2023-11-28 06:03:17 27 4
gpt4 key购买 nike

我正在尝试解析一个大文本文件并使用 Accordion 文本效果显示所有文本。这是结果:

enter image description here

正如您所看到的,对于小文本,没有问题,但是对于大文本......它无法正常工作。

如何添加滚动效果或使框变大以便正确显示所有文本内容?

jsfiddle: https://jsfiddle.net/jbfz09Ln/

代码:

html:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" lang="es-es">
<link rel="stylesheet" href="css/layout.css" type="text/css" media="screen">
<link rel="stylesheet" href="css/menu.css" type="text/css" media="screen">
<link rel="stylesheet" href="css/accordion.css" type="text/css" media="screen">

</head>
<body>
<!--Añadimos al area principal el efecto acordeon con el texto -->
<section class="mainArea" align="center">
<button class="accordion">Boot and Services</button>
<div id="placeholder" class="panelacc"></div>


</section>

<script>


/* nos permite gestionar los eventos para el texto en forma de acordeon */
var acc = document.getElementsByClassName("accordion");
for (var j = 0; j < acc.length; j++) {
acc[j].onclick = function(){
this.classList.toggle("active");
this.nextElementSibling.classList.toggle("show");
}
}



</script>
</body>
</html>

Accordion .css:

button.accordion {
background-color: #eee;
color: #444;
cursor: pointer;
padding: 18px;
width: 100%;
border: none;
text-align: left;
outline: none;
font-size: 15px;
transition: 0.4s;
}

button.accordion.active, button.accordion:hover {
background-color: #ddd;
}

button.accordion:after {
content: '\02795';
font-size: 13px;
color: #777;
float: right;
margin-left: 5px;
}

button.accordion.active:after {
content: "\2796";
}

div.panelacc {
padding: 0 18px;
background-color: white;
max-height: 0;
overflow: hidden;
transition: 0.6s ease-in-out;
opacity: 0;
}

div.panelacc.show {
opacity: 1;
max-height: 500px;
}

div.panelacc.show p {
color: black;
}

最佳答案

根据您的代码,您做错了两件事:

.mainArea{
height:300px; /* REMOVE this one */
border: 1px solid red;
}

/* AND */

div.panelacc.show {
opacity: 1;
max-height: 500px; /* HERE you are setting a fix height */
}

解决方案:删除 height:300px; 行并将 500px 更改为 100%,如下所示 max-height: 100% ;

check your code i have updated it

关于javascript - 如何根据内容调整 Accordion 文本大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37100673/

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