我正在为我的网站制作一个手风琴控件,它嵌套在一张卡片中,我在手风琴的标题上添加了一个盒子阴影,看起来不错,但是当我展开它时,主体会弹出一个阴影。 我想想的是一种在手风琴上留下阴影但在手风琴展开时不会使其弹出的方法。我已经建立了这个例子
/* CSS used here will be applied after bootstrap.css */
.recent-posts {
background: #D2C198;
margin-left: 400px;
margin-right: 400px;
}
.post-card {
background-color: #D2C198;
}
.reply-link,
.reply-link:hover,
.reply-link:active,
.reply-link:visited,
.user-post,
.user-post:hover,
.user-post:active,
.user-post:visited {
color: #222222;
text-decoration: none !important;
}
.card-header {
-webkit-box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
-moz-box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
.post-body {
-webkit-box-shadow: 0 0px 0px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
-moz-box-shadow: 0 0px 0px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
box-shadow: 0 0px 0px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
.post-reply {
padding-bottom: 10px;
}
.forum-image {
border-radius: 50%;
width: 100px;
height: 100px;
object-fit: cover;
}
.post-header {
padding-left: 30px;
height: 25px;
margin-left: 86px;
}
.post-divider {
border-bottom: 1px solid #222;
padding-top: 5px;
}
.avatar {
width: 50px;
height: 50px;
border-radius: 50%;
}
.header-forum-badge {
float: left;
}
.post-info {
padding-top: 10px;
}
.user-post {
display: inline-flex;
margin-left: 14px;
}
.user-post-avatar {
margin-right: 12px;
}
.post-views-replies {
float: right;
text-align: right;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<div class="card recent-posts">
<div class="card-body">
<div id="post-accordian">
<div class="card post-card">
<div class="card-header" id="post-heading" onmouseover="" data-toggle="collapse" data-target="#post-collapse" aria-expanded="true" aria-controls="post-collapse">
accordian header
</div>
<!-- Collapse panel -->
<div id="post-collapse" class="collapse post-container" aria-labelledby="post-heading" data-parent="#post-accordian">
<div class="card-body post-body">
<!-- collapse panel content -->
accordian body
<!-- End collapse panel content -->
</div>
</div>
</div>
</div>
</div>
</div>
是否有一种方法可以解决此问题,使其只是一个平滑的过渡,以便在扩展时看起来框阴影围绕着这两个元素?
答案 0 :(得分:1)
您肯定可以。只需将框阴影应用于其父元素。在这种情况下,.post-card
容器。
/* CSS used here will be applied after bootstrap.css */
.recent-posts {
background: #D2C198;
/*margin-left: 400px;
margin-right: 400px; disabled because it looks bad in SO snippet*/
}
.post-card {
background-color: #D2C198;
-webkit-box-shadow: 0 0px 0px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
-moz-box-shadow: 0 0px 0px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
box-shadow: 0 0px 0px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
.reply-link,
.reply-link:hover,
.reply-link:active,
.reply-link:visited,
.user-post,
.user-post:hover,
.user-post:active,
.user-post:visited {
color: #222222;
text-decoration: none !important;
}
/*.card-header {
-webkit-box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
-moz-box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
.post-body {
-webkit-box-shadow: 0 0px 0px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
-moz-box-shadow: 0 0px 0px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
box-shadow: 0 0px 0px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}*/
.post-reply {
padding-bottom: 10px;
}
.forum-image {
border-radius: 50%;
width: 100px;
height: 100px;
object-fit: cover;
}
.post-header {
padding-left: 30px;
height: 25px;
margin-left: 86px;
}
.post-divider {
border-bottom: 1px solid #222;
padding-top: 5px;
}
.avatar {
width: 50px;
height: 50px;
border-radius: 50%;
}
.header-forum-badge {
float: left;
}
.post-info {
padding-top: 10px;
}
.user-post {
display: inline-flex;
margin-left: 14px;
}
.user-post-avatar {
margin-right: 12px;
}
.post-views-replies {
float: right;
text-align: right;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<div class="card recent-posts">
<div class="card-body">
<div id="post-accordian">
<div class="card post-card">
<div class="card-header" id="post-heading" onmouseover="" data-toggle="collapse" data-target="#post-collapse" aria-expanded="true" aria-controls="post-collapse">
accordian header
</div>
<!-- Collapse panel -->
<div id="post-collapse" class="collapse post-container" aria-labelledby="post-heading" data-parent="#post-accordian">
<div class="card-body post-body">
<!-- collapse panel content -->
accordian body
<!-- End collapse panel content -->
</div>
</div>
</div>
</div>
</div>
</div>