gpt4 book ai didi

css - 无法正确显示 Accordion 折叠

转载 作者:行者123 更新时间:2023-11-27 23:22:16 25 4
gpt4 key购买 nike

Accordion 显示的结果没有响应

我正在学习折叠 Accordion 。我为正在创建的 Accordion 页面添加了 CSS。我已成功实现 Accordion Collapse,但结果没有响应。

我的代码是这样的

.MaskGrid {
margin-top: 24px;
margin-left: 24px;
width: 327px;
height: 80px;
border-radius: 5px;
box-shadow: 0 3px 5px 0 rgba(0, 0, 0, 0.05), 0 1px 18px 0 rgba(0, 0, 0, 0.05), 0 6px 10px 0 rgba(0, 0, 0, 0.05);
background-color: #ffffff;
}
.Prefilled {
margin-top: 16px;
margin-left: 16px;
margin-right: 16px;
margin-bottom: 16px;
width: 295px;
height: 48px;
background-color: transparent;
}
.box {
padding: 1.25rem;
-webkit-box-flex: 1;
-ms-flex: 1 1 auto;
flex: 1 1 auto;
width: 327px;
height: 317px;
border-radius: 5px;
box-shadow: 0 3px 5px 0 rgba(0, 0, 0, 0.05), 0 1px 18px 0 rgba(0, 0, 0, 0.05), 0 6px 10px 0 rgba(0, 0, 0, 0.05);
background-color: #ffffff;
}
.address---street-name {
width: 295px;
height: 280px;
font-family: sans-serif;
font-size: 13px;
font-weight: normal;
font-style: normal;
font-stretch: normal;
line-height: 1.54;
letter-spacing: normal;
color: #1f2d3d;
}
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<style type="text/css">
[aria-expanded="false"] > .expanded, [aria-expanded="true"] > .collapsed {
display: none;
}
</style>
</head>

<body>
<div class="container">
<div class="row" id="accordion">
<!-- one -->
<div class="MaskGrid">
<div class="Prefilled card-link" data-toggle="collapse" href="#menuone" aria-expanded="false" aria-controls="menuone">
<div class="NameText">Menu One</div>
<span class="collapsed"><i><img src="https://i.ibb.co/QXC72Qr/sa-arrow-down.png" class="sa-arrow-down"></i></span>
<span class="expanded"><i><img src="https://i.ibb.co/xzFDHvj/sa-arrow-up.png" class="sa-arrow-up"></i></span>
</div>
<div id="menuone" class="collapse">
<div class="card-body box">
<div class="address---street-name">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
</div>
</div>
</div>
<!-- two -->
<div class="MaskGrid">
<div class="Prefilled card-link" data-toggle="collapse" href="#menutwo" aria-expanded="false" aria-controls="menutwo">
<div class="NameText">Menu Two</div>
<span class="collapsed"><i><img src="https://i.ibb.co/QXC72Qr/sa-arrow-down.png" class="sa-arrow-down"></i></span>
<span class="expanded"><i><img src="https://i.ibb.co/xzFDHvj/sa-arrow-up.png" class="sa-arrow-up"></i></span>
</div>
<div id="menutwo" class="collapse">
<div class="card-body box">
<div class="address---street-name">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</body>

</html>

我想在选择 MenuOne 或 Menutwo 时制作 Accordion 菜单响应显示

谢谢

最佳答案

我对您的代码进行了一些修改,使其能够正确响应。

因为一些你需要知道的 Bootstrap 规则,比如 .row Bootstrap 类有一个 display: flex; 并且任何 flex div 都有子 div 所以子 div 也是采用display: flex;

因此,如果您没有在 flex 子元素中添加额外的 div,那么您的名为 .MaskGrid 的 div 将采用 display: flex;

如果 Accordion 数据不可见,那么在任何情况下,flex 兄弟 div 始终采用相同的高度。

就像下面的截图: enter image description here

此外,我已经为响应式设计添加了视口(viewport),如果您还没有添加,请添加。

修改后的代码如下:

HTML代码:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta name="viewport" content= "width=device-width, initial-scale=1.0"> <!-- added viewport for responsive design -->
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<style type="text/css">
[aria-expanded="false"] > .expanded, [aria-expanded="true"] > .collapsed {
display: none;
}
</style>
</head>

<body>
<div class="container">
<div class="row" id="accordion">
<div class="col-auto"> <!-- added extra parent div -->
<!-- one -->
<div class="MaskGrid">
<div class="Prefilled card-link" data-toggle="collapse" href="#menuone" aria-expanded="false" aria-controls="menuone">
<div class="NameText">Menu One</div>
<span class="collapsed"><i><img src="https://i.ibb.co/QXC72Qr/sa-arrow-down.png" class="sa-arrow-down"></i></span>
<span class="expanded"><i><img src="https://i.ibb.co/xzFDHvj/sa-arrow-up.png" class="sa-arrow-up"></i></span>
</div>
<div id="menuone" class="collapse">
<div class="card-body box">
<div class="address---street-name">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
</div>
</div>
</div>
<!-- two -->
</div>
<div class="col-auto"> <!-- added extra parent div -->
<div class="MaskGrid">
<div class="Prefilled card-link" data-toggle="collapse" href="#menutwo" aria-expanded="false" aria-controls="menutwo">
<div class="NameText">Menu Two</div>
<span class="collapsed"><i><img src="https://i.ibb.co/QXC72Qr/sa-arrow-down.png" class="sa-arrow-down"></i></span>
<span class="expanded"><i><img src="https://i.ibb.co/xzFDHvj/sa-arrow-up.png" class="sa-arrow-up"></i></span>
</div>
<div id="menutwo" class="collapse">
<div class="card-body box">
<div class="address---street-name">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</body>

</html>

CSS 代码:

.MaskGrid {
margin-top: 24px;
margin-left: 24px;
width: 327px;
height: auto; /*change 80px to auto*/
border-radius: 5px;
box-shadow: 0 3px 5px 0 rgba(0, 0, 0, 0.05), 0 1px 18px 0 rgba(0, 0, 0, 0.05), 0 6px 10px 0 rgba(0, 0, 0, 0.05);
background-color: #ffffff;
}
.Prefilled {
margin-top: 16px;
margin-left: 16px;
margin-right: 16px;
margin-bottom: 16px;
width: 295px;
height: 48px;
background-color: transparent;
}
.collapse.show .box { /*added .collapse.show*/
padding: 1.25rem;
-webkit-box-flex: 1;
-ms-flex: 1 1 auto;
flex: 1 1 auto;
width: 327px;
height: 317px;
border-radius: 5px;
box-shadow: 0 3px 5px 0 rgba(0, 0, 0, 0.05), 0 1px 18px 0 rgba(0, 0, 0, 0.05), 0 6px 10px 0 rgba(0, 0, 0, 0.05);
background-color: #ffffff;
}
.collapse.show .address---street-name { /*added .collapse.show*/
width: 295px;
height: 280px;
font-family: sans-serif;
font-size: 13px;
font-weight: normal;
font-style: normal;
font-stretch: normal;
line-height: 1.54;
letter-spacing: normal;
color: #1f2d3d;
}

请尝试此代码,如果您有任何问题,请告诉我。

关于css - 无法正确显示 Accordion 折叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57941118/

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