Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is this div not appearing when another div is focused?

I am working on a website, and I ran into a bug with my css. I am wanting a div to show when another div is focused. Why is it not working? Here is my code:

.explore-card-hidden-info {
    display: none;
}

.explore-card-light:focus .explore-card-hidden-info, .explore-card-hidden-info:hover {
    display: block;
}
<div>
    <div className="explore-card-light web-box-hor" style={props.style}>
        <div>
        <img src={props.src} alt="imgex" style={{width: "100%", margin: 'auto', height: 'auto'}}></img>
        </div>
        <div style={{marginLeft: '20px'}}>
            <p className="card-title" style={{textAlign: 'left'}}>{props.title}</p>
            <p className="card-main-text">{props.main}</p>
            <p className="card-footer-text">{props.ex}</p>
        </div>
        <div style={{marginLeft: '20px'}}>
            <p className="explore-card-footer-text" style={{margin: 'none'}}>rates: {props.rate}</p>
            <p className="explore-card-footer-text" style={{margin: 'none'}}>views: {props.views}</p>
            <p className="explore-card-footer-text" style={{margin: 'none'}}>purchases: {props.buys}</p>
        </div>
        <div style={{ padding: '30px 150px' }}>
            <p className="card-title">{props.money}</p>
            <OpBtnOutlineRound text="Buy"></OpBtnOutlineRound>
        </div>
    </div>
    <div className="explore-card-hidden-info">
        <h2>
            I adm hidden!
        </h2>
    </div>
</div>
.explore-card-light {
    background-color: var(--card-bg-light);
    border-radius: 0px 7px 7px 0px;
    padding: 25px;
    width: 95%;
    margin: 20px;
    border-left: 10px solid var(--second);
    position: relative;
    right: 0px;
    transition: all 0.4s ease;
    align-items: center;
    justify-content: space-between;
}
.explore-card-hidden-info {
    display: none;
}

I got it to work with focus on another thing on the website, but it is not wanting to work on this one!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

.explore-card-hidden-info is not a descendant of .explore-card-light, it’s an adjacent element. Use + to represent that in CSS.

To make a DIV focusable from the mouse, you need to give it a tabindex.

.explore-card-hidden-info {
    display: none;
}

.explore-card-light:focus + .explore-card-hidden-info {
    display: block;
}
<div>
  <div class="explore-card-light web-box-hor" style={props.style} tabindex="1">
    <div>
      <img src={props.src} alt="imgex" style={{width: "100%", margin: 'auto', height: 'auto'}}></img>
    </div>
    <div style={{marginLeft: '20px'}}>
      <p class="card-title" style={{textAlign: 'left'}}>{props.title}</p>
      <p class="card-main-text">{props.main}</p>
      <p class="card-footer-text">{props.ex}</p>
    </div>
    <div style={{marginLeft: '20px'}}>
      <p class="explore-card-footer-text" style={{margin: 'none'}}>rates: {props.rate}</p>
      <p class="explore-card-footer-text" style={{margin: 'none'}}>views: {props.views}</p>
      <p class="explore-card-footer-text" style={{margin: 'none'}}>purchases: {props.buys}</p>
    </div>
    <div style={{ padding: '30px 150px' }}>
      <p class="card-title">{props.money}</p>
      <OpBtnOutlineRound text="Buy"></OpBtnOutlineRound>
    </div>
  </div>
  <div class="explore-card-hidden-info">
    <h2>
      I adm hidden!
    </h2>
  </div>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading