I wanted to change the background when I hover over the card. I had tried to add hover class but it is not working, so I am here now founding this community.
@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 >Cards</h1>
<div >
<section role="button" tabindex="0">
<span >Sports, Chess</span>
<div >
<p >Mankuda Giri</p>
<p >Chess Grand Master</p>
</div>
<p >India</p>
</section>
</div>
</main>
I wanted to add any color in the background. Sorry for any inconvenience in the way my I posted the question. This is my first question on SO. Thanks in advance.
CodePudding user response:
You can use :hover to change the background colour.
@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;
}
.card-container:hover,
.card-container:focus,
.card-container:active {
background-color: crimson;
border-color: crimson;
box-shadow: rgba(220, 20, 60, 0.699) 0px 48px 100px 0px;
}
.showcase {
display: flex;
justify-content: center;
}
@media screen and (max-width: 710px) {
.showcase {
flex-direction: column;
}
}
<main>
<h1 >Cards</h1>
<div >
<section role="button" tabindex="0">
<span >Sports, Chess</span>
<div >
<p >Mankuda Giri</p>
<p >Chess Grand Master</p>
</div>
<p >India</p>
</section>
</div>
</main>
CodePudding user response:
if you wish to change card's background when hover, you can add this to your css:
.card-container:hover {
background: cadetblue;
}
CodePudding user response:
Use this
.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 >Cards</h1>
<div >
<section role="button" tabindex="0">
<span >Sports, Chess</span>
<div >
<p >Mankuda Giri</p>
<p >Chess Grand Master</p>
</div>
<p >India</p>
</section>
</div>
</main>
CodePudding user response:
You can use :hover state to add hover effect on card
.card-container:hover {
background: green;
}
CodePudding user response:
.card-container:hover {
background-color: blue;
}
Just add this CSS and done
CodePudding user response:
You need to use :hover selector is used to select elements when you mouse over them
section.card-container:hover{
background:#969696;
}
CodePudding user response:
You can use :hover after the css class and change the background color
.card-container:hover{background-color: blue;}
