アップデート:新しい要件に
、トランジション効果が異なることが必要であり、以下のスニペットを参照してください。
.container {
width: 250px;
height: 300px;
background: #00f;
position: relative;
}
.show {
position: absolute;
opacity:0;
height:30%;
bottom:0px;
left:0px;
right:0px;
color: #000;
text-indent: 5px;
background: rgba(255, 255, 255, .5);
transition: opacity 0.5s ease-in-out;
}
.container:hover>.show {
opacity:1;
}
<div class="container">
<div class="show">Lorem </div>
</div>
旧回答:問題が
transition
プロパティは、CSSプロパティ
display:none
に適用することはできませんされて
、これを回避するには、最初に0PXする高さを設定することで、あなたが直面する問題は、テキストがまだ画面に表示されるということです。このオーバーフローするテキストを非表示にするには、CSSクラスoverflow:hidden
を使用して、要素の外にあるコンテンツを非表示にします。また、親要素でtransitionを使用する代わりに、要素自体で直接transitionを使用します。以下のクラスを参照してください。
.show{
position:absolute;
overflow:hidden;
bottom:0;
height:0px;
width:100%;
color:#000;
text-indent:5px;
background:rgba(255,255,255,.5);
transition: height 1s ease-in-out;
}
遷移プロパティは次のとおりです。
transition: height 1s ease-in-out;
最初に、どのプロパティにトランジション効果があるかを明記してください。その後、移行の継続時間は、ease-in
か他の設定かどうか。
次に、ホバー上で元の高さを設定します。移行が表示されます。
.container:hover > .show{
height:50%;
}
.container {
width: 250px;
height: 300px;
background: #00f;
position: relative;
}
.show {
position: absolute;
overflow: hidden;
bottom: 0;
height: 0px;
width: 100%;
color: #000;
text-indent: 5px;
background: rgba(255, 255, 255, .5);
transition: height 1s ease-in-out;
}
.container:hover>.show {
height: 50%;
}
<div class="container">
<div class="show">Lorem </div>
</div>
あなたが答えてくれてありがとう、私は異なる 'アニメーション' について考えていました。私はそれのようなsthを取得しようとしています:https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_image_overlay_opacity しかし、30%の高さです。 このエフェクトは 'スライドイン(ボトム)'のようなものではありません。「フェードインボックス」の例を得ようとしています。 https://www.w3schools.com/howto/howto_css_image_overlay.asp – Misiek777
@ Misiek777私の答えが更新されました。あなたの質問にすべて言及してください。あなたが上から見えるようにするには、ボックスを 'show:'の 'top:0px'に変更します。 –