单击按钮时,卡片将按类别进行过滤。如何使我的4张卡片显示如下:每两行两张卡片,无论是使用Bootstrap还是纯CSS,仍然能够过滤它们,并在单击每个按钮时正确显示它们?
当前每行有一张卡,共有4行。我已经尝试过使用Bootstrap,但是它弄乱了卡片,使我无法正确过滤它们。一行上显示了两张卡,但它们完全重叠,我正在努力进行更改,所有四张卡都有第一张图像。
$(document).ready(function () {
let $btns = $('.projects .button-group button');
$btns.click(function (e) {
$('.projects .button-group button').removeClass('active');
e.target.classList.add('active');
let selector = $(e.target).attr('data-filter');
$('.projects .grid').isotope({
filter: selector
});
return false;
})
$('.projects .button-group #btn1').trigger('click');
})
.link {
height: 425px;
margin-bottom: 50px;
&:hover {
text-decoration: none;
.project_title {
text-decoration: underline;
}
}
}
.wrapper {
max-width: 850px;
margin: 20px auto;
height: auto;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-around;
}
.card_wrapper {
width: 460px;
transition: transform 0.5s;
position: relative;
margin: 4rem 3rem;
border-radius: 6px;
background: #e4f2f9;
display: flex;
flex-direction: column;
background: url("image");
background-size: contain;
background-repeat: no-repeat;
}
a:nth-of-type(2) .card_wrapper {
background-image: url("image");
}
a:nth-of-type(3) .card_wrapper {
background-image: url("image");
}
a:nth-of-type(4) .card_wrapper {
background-image: url("image");
}
.project_summary {
margin-top: 260px;
position: relative;
padding: 0 20px;
flex: 1;
border-bottom-left-radius: inherit;
border-bottom-right-radius: inherit;
text-align: center;
}
.project_title {
margin-bottom: 0;
padding: 0 0.5rem 1rem 0.5rem;
}
.testimonials {
margin-top: 16%;
}
.project-btn {
margin: 1rem;
color: white;
background-color: orange;
border: none;
border-radius: 10%;
font-size: 14px;
padding: 0.4rem 0.8rem;
&:hover {
color: $navy-blue;
background: none;
border: 2px solid orange;
}
}
.project-category {
color: orange;
background: white;
text-decoration: underline;
border: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="button-group">
<button type="button" class="project-category active text-uppercase">All</button>
<button type="button" class="project-category text-uppercase" data-filter=".latest">Latest</button>
<button type="button" class="project-category text-uppercase" data-filter=".frontend">Front End</button>
<button type="button" class="project-category text-uppercase" data-filter=".fullstack">Full Stack</button>
</div>
<div class="row grid">
<a href="#" class="link fullstack latest">
<article class="card_wrapper">
<div class="project_summary">
<h2 class="project_title">project 1</h2>
<p class="project_desc text-secondary">
project 1 description</p>
<button id="ecommerce-code" class="project-btn text-uppercase">View code</button>
<button class="project-btn text-uppercase" id="ecommerce-more">View More</button>
</div>
</article>
</a>
<a href="#" class="link frontend">
<article class="card_wrapper">
<div class="project_summary">
<h2 class="project_title">project 2</h2>
<p class="project_desc para">project 2 description</p>
<button class="project-btn text-uppercase" id="portfolio-code">View code</button>
</div>
</article>
</a>
<a href="#" class="link frontend">
<article class="card_wrapper">
<div class="project_summary">
<h2 class="project_title">project 3 </h2>
<p class="project_desc text-secondary">
project 3 description</p>
<button class="project-btn text-uppercase" id="devscreate-code">View code</button>
<button class="project-btn text-uppercase" id="devscreate-site">Live Website</button>
</div>
</article>
</a>
<a href="#" class="link frontend">
<article class="card_wrapper">
<div class="project_summary">
<h2 class="project_title">project 4</h2>
<p class="project_desc text-secondary">
project 4 description</p>
<button class="project-btn text-uppercase" id="boozles-code">View code</button>
<button class="project-btn text-uppercase" id="boozles-site">Live Website</button>
</div>
</article>
</a>
</div>