gpt4 book ai didi

css - 使用css获取兄弟html元素以占用整个父容器

转载 作者:行者123 更新时间:2023-11-28 12:13:08 25 4
gpt4 key购买 nike

当下面的代码在 fiddle 中运行时元素“.title-wrap”和“.bg-wrap”并排出现。任何人都可以告诉我如何使“.bg-wrap”自动占据整个“.wrap”并进行最少的 css 更改。

html:

<div class="wrap selected">
<div class="title-wrap"></div>
<div class="bg-wrap"></div>
</div>

CSS:

.selected .title-wrap{
position:initial !important;
text-align: center;
height:29.42px;
animation:titleAnimation .2s;
-webkit-animation:titleAnimation .2s;
-webkit-animation-fill-mode: forwards;
}

@-webkit-keyframes titleAnimation
{
from {left:85px;top:5px}
to {left:25px;top:5px}
}

.wrap .title-wrap{
width:202px;
display:block;
position:absolute;
top:5px;
left:85px;
background:black;
}


.selected .bg-wrap{
background:green;
height:700px;
width:100%;
animation:bgAnimation .2s;
-webkit-animation:bgAnimation .2s;
-webkit-animation-fill-mode: forwards;
}

@-webkit-keyframes bgAnimation
{
from {left:85px;top:35px;}
to {left:205px;top:0px;}
}

.wrap .bg-wrap{
display:block;
position:absolute;
top:35px;
left:85px;
}

最佳答案

对您试图完成的事情并不乐观,但我认为我有解决方案。我还清理了你的代码,它现在被缩小并且更容易阅读。我还针对跨浏览器使用进行了更新。这是更新后的 JSFiddle,其中包含必要的修复:http://jsfiddle.net/mLh7r/34/

HTML:

<div class="wrap selected">
<div class="title-wrap titleAnimation"></div>
<div class="bg-wrap bgAnimation"></div>
</div>

CSS:

@-webkit-keyframes titleAnimation {from{left:85px;top:5px}to{left:25px;top:5px}}
@-moz-keyframes titleAnimation {from{left:85px;top:5px}to{left:25px;top:5px}}
@keyframes titleAnimation {from{left:85px;top:5px}to{left:25px;top:5px}}

@-webkit-keyframes bgAnimation {from{left:85px;top:35px;}to{left:0px;top:0px;}}
@-moz-keyframes bgAnimation {from{left:85px;top:35px;}to{left:0px;top:0px;}}
@keyframes bgAnimation {from{left:85px;top:35px;}to{left:0px;top:0px;}}

.titleAnimation {
-webkit-animation: titleAnimation ease-in 1s;
-moz-animation: titleAnimation ease-in 1s;
animation: titleAnimation ease-in 1s;

-webkit-animation-fill-mode: forwards;
-moz-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
.bgAnimation {
-webkit-animation: bgAnimation ease-in 1s;
-moz-animation: bgAnimation ease-in 1s;
animation: bgAnimation ease-in 1s;

-webkit-animation-fill-mode: forwards;
-moz-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
.wrap .title-wrap, .wrap .bg-wrap {
position: absolute;
display: block;
left: 85px;
}
.title-wrap {
position:absolute !important;
text-align: center;
height:29.42px;
}
.bg-wrap {
height:700px;
width:100%;
background:green;
z-index: -1;
}
.wrap .title-wrap {
width:202px;
top:5px;
background:black;
}
.wrap .bg-wrap {
top:35px;
}

关于css - 使用css获取兄弟html元素以占用整个父容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19370159/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com