0

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 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>

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.

Temani Afif
  • 245,468
  • 26
  • 309
  • 415
  • do you want to change bg of card when you hover over the card? you can use :hover for this. – aekit Jan 05 '22 at 06:45
  • You can add styles in ".card-container:hover" which will be called when you hover over the DOM object having this class. – jaybhatt Jan 05 '22 at 06:46
  • 1
    Does this answer your question? [How to use 'hover' in CSS](https://stackoverflow.com/questions/905033/how-to-use-hover-in-css) – aekit Jan 05 '22 at 06:51

6 Answers6

0

if you wish to change card's background when hover, you can add this to your css:

.card-container:hover {
    background: cadetblue;
  }
seantsang
  • 1,123
  • 2
  • 7
  • 20
0

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 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>
Monika Virmani
  • 431
  • 2
  • 10
0

You can use :hover state to add hover effect on card

.card-container:hover {
    background: green;
}
Arul Prabakaran
  • 135
  • 2
  • 8
0
.card-container:hover {
  background-color: blue;
}

Just add this CSS and done

0

You need to use :hover selector is used to select elements when you mouse over them

section.card-container:hover{
background:#969696;
}
0

You can use :hover after the css class and change the background color

.card-container:hover{background-color: blue;}
Rakib Hossain
  • 61
  • 1
  • 3