设置导航栏fixed的问题,子元素不能随父元素固定?

html代码如下

<div class="banner clearf">
    <div class="logo">
        <a href= "lbt.html" id="logo">乎之</a>
    </div>
    <div class="banner-container ">
        <div class="item">1</div>
        <div class="item">2</div>
        <div class="item">3</div>
    </div>
</div>

css如下
.banner{

width: 100%;
display: block;
position: fixed;
top: 0;
background-color: rgba(255, 255, 255, 1);
height: 70px;
box-shadow:0 3px 5px rgb(118, 231, 217);
border-radius: 1px;
z-index: 100;

}

logo {

display: block;
text-decoration: none;
height: 70px;
margin-left: 15%;
color: rgb(104, 105, 236);
font-size: 3em;

}
.clearf::after{

clear: both;

}
.clearf::before{

clear: both;

}
.banner-container {

top: -100px;
height: 100%;
width: auto;
border: 1px solid black;
border-color: rgb(110, 56, 28);

}
.banner-container .item{

float: left;

}

banner-container里面的内容不能随父级div banner固定在顶部
请问哪里出了问题
定位position问题还是float的问题?

clipboard.png

阅读 4k
3 个回答

怎么不能固定了,可以的啊

logo的display:inline-block.
block会占据行。
你给的码不全,css的logo是a的吗?这样写很不规范耶

新手上路,请多包涵

你给.banner{height:70px;} .banner-container{height:70px; } 父级都装不下了你说他换行不

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题