CSS-如何制作动态的引导列表可滚动
我在VUE应用程序中有此代码,
<form class="d-flex me-auto" id="searchBar">
<div class="input-group">
<input class="form-control" type="text" placeholder="Cerca professionista" @keyup="search" aria-label="Search" v-model="searchInput">
<button class="btn btn-outline-success" @click.prevent="search">
<i class="fa-solid fa-search"></i>
</button>
</div>
</form>
<div class="list-group" v-if="searchResults.length > 0" id="searchResultsList">
<a href="#" class="list-group-item list-group-item-action" v-for="(result, index) in searchResults" :key="index" id="searchResult" @click.prevent="showUserProfile(result.username)">
<div class="d-flex w-100 justify-content-between">
<p class="ps-2 me-auto mb-1">{{ result.name }} {{ result.surname }}</p>
<!-- <img :src="result.propicUrl" id="searchResultThumbnail"> -->
</div>
<small class="ps-2 me-auto">{{ result.category }}</small>
</a>
</div>
我将有一个列表,其中包含搜索结果,因为有很多结果,如何使其可以滚动?目前,我添加了此CSS规则,但不起作用
<style lang="scss">
#menu {
height: 75px;
.navbar-brand {
padding-top: 0;
#logo {
width: 60px;
height: 60px;
}
}
#searchBar {
width: 420px;
}
#searchResultsList {
position: absolute;
top: 3.8em;
left: 5.4em;
width: 420px;
overflow-y: scroll;
#searchResult {
overflow-y: scroll;
#searchResultThumbnail {
height: 40px;
width: 40px;
border-radius: 50%;
}
}
}
}
</style>
I have this code in my vue app
<form class="d-flex me-auto" id="searchBar">
<div class="input-group">
<input class="form-control" type="text" placeholder="Cerca professionista" @keyup="search" aria-label="Search" v-model="searchInput">
<button class="btn btn-outline-success" @click.prevent="search">
<i class="fa-solid fa-search"></i>
</button>
</div>
</form>
<div class="list-group" v-if="searchResults.length > 0" id="searchResultsList">
<a href="#" class="list-group-item list-group-item-action" v-for="(result, index) in searchResults" :key="index" id="searchResult" @click.prevent="showUserProfile(result.username)">
<div class="d-flex w-100 justify-content-between">
<p class="ps-2 me-auto mb-1">{{ result.name }} {{ result.surname }}</p>
<!-- <img :src="result.propicUrl" id="searchResultThumbnail"> -->
</div>
<small class="ps-2 me-auto">{{ result.category }}</small>
</a>
</div>
I will have a list that will contain the results of a search, since there are a lot of results, how I can make it scrollable? At the moment I have added this css rules but not working
<style lang="scss">
#menu {
height: 75px;
.navbar-brand {
padding-top: 0;
#logo {
width: 60px;
height: 60px;
}
}
#searchBar {
width: 420px;
}
#searchResultsList {
position: absolute;
top: 3.8em;
left: 5.4em;
width: 420px;
overflow-y: scroll;
#searchResult {
overflow-y: scroll;
#searchResultThumbnail {
height: 40px;
width: 40px;
border-radius: 50%;
}
}
}
}
</style>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将
高度
或max-height
设置为导致具体大小的值(例如:40VW
,200px < /code>,
20pt
)用于溢出Y:自动|滚动
有任何效果。如果不设置
(max-)高度
,则该元素将增长以匹配其孩子的高度,并且永远不会显示活动的滚动栏。旁注:考虑元素具有
位置:绝对
,高度:100%
可能会将高度请求委派给最近的定位的祖先但是,您确实需要一个带有 concrete concrete Height的位置祖先,Overfloflflow y :自动|滚动
工作。通用示例:
操场:
设置
高度
和Max-height
之间的区别在于,即使没有足够的内容,元素即使它具有指定的高度也将具有指定的高度要填写它,而使用Max-Height
,当您没有足够的内容时,该元素将一直缩小到0
(除非其他东西给它一个软最小值
:例如:flex容器)。You need to set either
height
ormax-height
to a value that results in a concrete size (e.g:40vw
,200px
,20pt
) foroverflow-y: auto | scroll
to have any effect.Without setting the
(max-)height
, the element will grow to match the height of its children and will never display an active scrollbar.Side note: considering the element has
position: absolute
,height: 100%
will likely delegate the height request to the closest positioned ancestor but, again, you do need a positioned ancestor with a concrete height foroverflow-y: auto | scroll
to work.Generic example:
Playground:
The difference between setting
height
andmax-height
is that withheight
the element will have the specified height even when it doesn't have enough content to fill it, while withmax-height
, when you don't have enough content, the element will shrink all the way down to0
(unless something else gives it a softmin-height
: e.g: a flex container).