Hier ist die fiddle.Wie zur absoluten Position: vor dem Pseudoelement des Kindes relativ zum Elternteil?
Ich habe zwei div-Elemente.
<div class="parent">
<div class="child">
</div>
</div>
und CSS-Code für das.
.parent {
height: 20px;
width: 100px;
background-color: #080;
position: relative;
}
.child {
position: absolute;
width: 80px;
height: 200px;
background-color: #008;
right: -10px;
top: 30px;
}
.child:before {
border-right: 10px solid transparent;
border-bottom: 10px solid #008;
border-left: 10px solid transparent;
top: -10px;
width: 0;
height: 0;
content: "";
position: absolute;
left: 50%;
}
Wie .parent
ohne JS .child:before
Bezug zu positionieren. Ich kenne die Lösung mit .parent:before
, aber es ist nicht gut für mich.
Während die '.child' div andere einen Positionswert von etwas hat als' static' dies mit CSS nicht möglich ist. Es ist nicht klar, was Sie versuchen oder warum. –
@Paulie_D Ich versuche, '.child: before' relativ zu den Eltern zu zentrieren. Ohne Verwendung von "parent: before". – cassln
Ja ... aber warum? Was ist los mit '.parent: before'? Wie gesagt, das ist mit CSS nicht möglich. –