[英]CSS: Topbar not following the scrolling of the page
I know there may be a solution out the for my problem but because its a specific code i decided to make a post and ask for help, so lets get started 我知道可能有一个针对我的问题的解决方案,但是因为它是特定代码,所以我决定发布一个帖子并寻求帮助,所以让我们开始吧
I have a topbar (like a banner) that needs to follow the scrolling but it doesn't it stays in one position and it doesn't move i already tried position:fixed
and width:100%
but it adds a little empty space on the top of the page 我有一个顶部栏(如横幅),需要跟随滚动,但是它没有停留在一个位置并且它不会移动,我已经尝试过
position:fixed
和width:100%
但在上面添加了一些空白页面顶部
This is my css code: 这是我的CSS代码:
.topBar{
height: 50px;
overflow: hidden;
list-style-type: none;
margin-left: -10px;
margin-top: -10px;
margin-right: -8px;
padding: 0;
background-color: #111;
z-index: 1;
background-image : url("image.png");
background-repeat: no-repeat;
background-size: contain;
background-position: center;
}
This is the code where i load the topbar in the header: 这是我在标题中加载顶部栏的代码:
<ul class="topBar">
<li class="topBarItems" style="float: right; color: #fff; padding-top: 15px; padding: 8px 15px; font-size: 25px;"><i class="fa fa-user" aria-hidden="true"></i> <?php echo $username?></li>
</ul>
This is my desired result, here the position and width is not set but there it doesn't follow the scrolling 这是我想要的结果,这里没有设置位置和宽度,但是没有跟随滚动
This is what happens when i apply position:fixed and width:100%, there is a white bar added on top and the scrolling works just fine 当我应用position:fixed和width:100%时,会发生这种情况,顶部添加了一个白色条,并且滚动效果很好
Is this what you want? 这是你想要的吗?
https://jsfiddle.net/15416xb1/4/ https://jsfiddle.net/15416xb1/4/
.topBar {
height: 50px;
width: 100%;
overflow: hidden;
list-style-type: none;
margin-left: -10px;
margin-top: -10px;
margin-right: -8px;
padding: 0;
background-color: #111;
position: fixed;
top: 0;
z-index: 1;
background-image: url("image.png");
background-repeat: no-repeat;
background-size: contain;
background-position: center;
}
I do not get the white space at the top 我没有顶部的空白
.topbar {
height: 50px;
position: fixed;
top: 0;
left: 0;
width: 100%;
min-width: 500px;
z-index: 99999;
}
html.is-topbar {
padding-top: 50px;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.