当我在卡片上盘旋时,我想改变背景。我曾试图添加悬浮类,但它不起作用,所以我现在在这里创建这个社区。
@import url("https://fonts.googleapis.com/css2?family=Work+Sans:wght@400;500;700&display=swap");
*,
*::before,
*::after {
box-sizing: border-box;
padding: 0;
margin: 0;
}
:root {
--default-text-color: white;
--default-border-color: white;
--hover-background: rgba(220, 20, 60, 0.699) 0px 48px 100px 0px;
--hover-color: crimson;
}
p,
h1,
h6,
span {
font-family: "Work Sans", sans-serif;
}
html {
background-color: black;
}
.title {
text-align: center;
font-weight: 400;
font-size: 3rem;
color: white;
}
.job-role {
text-align: center;
font-weight: 500;
font-size: 2.8rem;
letter-spacing: -0.2rem;
position: relative;
bottom: 20%;
}
.job-label {
border: 1px solid transparent;
border-radius: 1.1rem;
margin: 2rem;
padding: 0.5rem;
font-weight: 500;
background-color: rgba(255, 255, 255, 0.2);
color: var(--default-text-color);
}
.job-title {
color: var(--default-text-color);
}
.job-description {
color: rgba(255, 255, 255, 0.3);
}
.location {
font-weight: 500;
font-size: 1.2rem;
font-style: bold;
color: var(--default-text-color);
margin: 1rem;
}
.card-container {
border: 1px solid var(--default-border-color);
border-radius: 1.1rem;
max-width: 350px;
height: 30rem;
margin: 1.2rem;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
position: relative;
transition: 300ms linear all;
}
.showcase {
display: flex;
justify-content: center;
}
@media screen and (max-width: 710px) {
.showcase {
flex-direction: column;
}
}<main>
<h1 class="title">Cards</h1>
<div class="showcase">
<section class="card-container card-1" role="button" tabindex="0">
<span class="job-label">Sports, Chess</span>
<div class="job-role">
<p class="job-title">Mankuda Giri</p>
<p class="job-description">Chess Grand Master</p>
</div>
<p class="location">India</p>
</section>
</div>
</main>
我想在背景中添加任何颜色。很抱歉,我发布这个问题的方式给我带来不便。这是我的第一个问题。提前谢谢。
发布于 2022-01-05 06:46:23
如果您希望在悬停时更改卡的背景,可以将其添加到css中:
.card-container:hover {
background: cadetblue;
}发布于 2022-01-05 06:47:21
使用这个
.showcase .card-1:hover{
background-color:green;
}
@import url("https://fonts.googleapis.com/css2?family=Work+Sans:wght@400;500;700&display=swap");
*,
*::before,
*::after {
box-sizing: border-box;
padding: 0;
margin: 0;
}
:root {
--default-text-color: white;
--default-border-color: white;
--hover-background: rgba(220, 20, 60, 0.699) 0px 48px 100px 0px;
--hover-color: crimson;
}
p,
h1,
h6,
span {
font-family: "Work Sans", sans-serif;
}
html {
background-color: black;
}
.title {
text-align: center;
font-weight: 400;
font-size: 3rem;
color: white;
}
.job-role {
text-align: center;
font-weight: 500;
font-size: 2.8rem;
letter-spacing: -0.2rem;
position: relative;
bottom: 20%;
}
.job-label {
border: 1px solid transparent;
border-radius: 1.1rem;
margin: 2rem;
padding: 0.5rem;
font-weight: 500;
background-color: rgba(255, 255, 255, 0.2);
color: var(--default-text-color);
}
.job-title {
color: var(--default-text-color);
}
.job-description {
color: rgba(255, 255, 255, 0.3);
}
.location {
font-weight: 500;
font-size: 1.2rem;
font-style: bold;
color: var(--default-text-color);
margin: 1rem;
}
.card-container {
border: 1px solid var(--default-border-color);
border-radius: 1.1rem;
max-width: 350px;
height: 30rem;
margin: 1.2rem;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
position: relative;
transition: 300ms linear all;
}
.showcase {
display: flex;
justify-content: center;
}
.showcase .card-1:hover{
background-color:green;
}
@media screen and (max-width: 710px) {
.showcase {
flex-direction: column;
}
}<main>
<h1 class="title">Cards</h1>
<div class="showcase">
<section class="card-container card-1" role="button" tabindex="0">
<span class="job-label">Sports, Chess</span>
<div class="job-role">
<p class="job-title">Mankuda Giri</p>
<p class="job-description">Chess Grand Master</p>
</div>
<p class="location">India</p>
</section>
</div>
</main>
发布于 2022-01-05 06:47:54
您可以使用:hover状态在卡上添加悬停效果。
.card-container:hover {
background: green;
}https://stackoverflow.com/questions/70588748
复制相似问题