suchen

Heim  >  Fragen und Antworten  >  Hauptteil

So beschränken Sie CSS so, dass es nur für ein Div in derselben Kategorie wirksam wird

Ich versuche, den Titel beim Mouseover über dem Bild erscheinen zu lassen, aber sie müssen alle die gleiche Klasse haben. Ich weiß nicht, ob das, was ich frage, möglich ist, aber ich würde verschiedene Lösungen in Betracht ziehen. Das ist mein aktueller Code.

<div class="item">
            <img class="Placeholderimg" src="placeholder.jpg">
            <div class="hovershow1">
                <div class="title">
                    Testing1
                </div>
            </div>
        </a>
    </div>
    <div class="item">
        <img class="Placeholderimg" src="placeholder.jpg">
        <div class="hovershow2">
            <div class="title">
                Testing2
            </div>
        </div>

Das ist mein CSS-Code

.item{
    height: 156px;
    width: 156px;
}

.Placeholderimg{
    height: 156px;
    width: 156px;
    border-radius: 10px;
}

.hovershow1{
    visibility: hidden;
    position: absolute;
    top:0;
    height: 156px;
    width:156px;
    background-color: rgba(40, 40, 40, 0.4);
    border-radius: 10px;
}

.item:hover .hovershow1{
    visibility:visible;
}

.hovershow2{
    visibility: hidden;
    position: absolute;
    top:0;
    height: 156px;
    width:156px;
    background-color: rgba(40, 40, 40, 0.4);
    border-radius: 10px;
}

.item:hover .hovershow2{
    visibility:visible;
}
P粉475315142P粉475315142533 Tage vor566

Antworte allen(1)Ich werde antworten

  • P粉709644700

    P粉7096447002023-09-10 15:21:29

    我只是不得不将位置更改为相对位置,这是我的代码

    .item{
        height: 156px;
        width: 156px;
    }
    
    .Placeholderimg{
        height: 156px;
        width: 156px;
        border-radius: 10px;
    }
    
    .hovershow{
        visibility: hidden;
        position: relative;
        height: 156px;
        width:156px;
        background-color: rgba(40, 40, 40, 0.4);
        border-radius: 10px;
    }
    
    .item:hover .hovershow{
        visibility:visible;
    }

    Antwort
    0
  • StornierenAntwort