У меня проблема с начальной загрузкой, потому что мне нужно оставить статическую строку поиска, как показано ниже:
Для этого я используюследующий код:
HTML:
<nav class="navbar fixed-top navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
</nav>
<div class="list-page">
<div class="row-search-bar">
<div class="pos-rel">
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="Recipient's username" aria-label="Recipient's username" aria-describedby="basic-addon2">
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button">Button</button>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
<p>This is an element that is part of the list of results</p>
</div>
</div>
</div>
CSS:
@media (max-width: 575.98px) {
.list-page {
padding-top: 24%;
margin-left: 10%;
margin-right: 10%;
}
}
/* Small devices (landscape phones, 576px and up)*/
@media (min-width: 576px) and (max-width: 767.98px) {
.list-page {
padding-top: 14%;
margin-left: 10%;
margin-right: 10%;
}
}
/*Medium devices (tablets, 768px and up)*/
@media (min-width: 768px) and (max-width: 991.98px) {
.list-page {
padding-top: 7%;
margin-left: 10%;
margin-right: 10%;
}
}
/*Large devices (desktops, 992px and up)*/
@media (min-width: 992px) and (max-width: 1199.98px) {
.list-page {
padding-top: 6%;
margin-left: 10%;
margin-right: 10%;
}
}
/*Extra large devices (large desktops, 1200px and up)*/
@media (min-width: 1200px) {
.list-page {
padding-top: 6%;
margin-left: 10%;
margin-right: 10%;
}
}
.pos-rel{
position: relative;
width:100%;
}
.row-search-bar{
position: relative;
z-index: 1030;
background-color:red;
}
Важная часть моего предыдущего кодазаключается в том, что он использует свойство position: relative;
в классе row-search-bar
css, но когда вы перемещаете содержимое страницы, эта панель поиска не остается на месте, она перемещается вместе с содержимым.Для вышеизложенного, чтобы достичь цели сохранения панели поиска, я использую position: fixed;
в классе row-search-bar
css, но это происходит:
Итак, что я должен сделать, чтобы панель поиска оставалась на месте, когда я прокручиваю вверх / вниз, и строка поиска выглядит следующим образом:
Большое спасибо!