I'm trying to make a button that has an image background and text. The text should be invisible and the bg image should be opaque. When you hover the button, the background should go black and the text appear at the same time, with a fading transition, but I cant get only one to display at a time.
I tried adding the text inside the tablet div, seperate to the code_block div but it just displays beside the image. Then I tried adding the text inside the code_block div and it made the image disappear completely. I know I need to have the text display set as none until I hover over it, but I'm not sure how to set the display to block when I want it to display.
Here's the HTML:
<div class="content_container">
<div class="tablet"><p id="text">Text</p><div id="code_block"></div></div>
<div class="tablet"></div>
<div class="tablet"></div>
<div class="tablet"></div>
</div>
And here's the css:
.content_container {
display: flex;
justify-content: space-evenly;
}
.tablet {
display: inline-flex;
margin-top: 5vh;
/*Height restraints*/
height: var(--medium);
max-height: var(--med-ub);
min-height: var(--med-small-lb);
/*Width restraints*/
width: var(--med-large);
max-width: var(--med-large-ub);
min-width: var(--med-large-lb);
/*Margins*/
margin-right: 1vw;
margin-left: 1vw;
background-color: var(--primary_colour);
border: solid 1px var(--tirtiary_colour);
border-radius: 1vw;
transition: 1s;
}
#code_block {
opacity: 1;
background-image: url("img/code_pic.png");
background-color: rgba(0,0,0,0.5);
background-size: cover;
background-repeat: no-repeat;
transition: opacity 1s ease;
}
#code_block:hover {
opacity: 0;
transition: opacity 1s ease;
}
.tablet:hover {
width: var(--large);
height: var(--medium);
transition: 1s;
}
#text {
display: none;
}
#text:hover {
display: block;
}
Going with the code you provided (and with defining the CSS variables which were not defined in your code), you can do it like this. The comments are within the code (CSS), an they begin with
this is new.