You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将Quasar q-scroll-area内的行定位到侧边栏底部?

解决Quasar侧边栏底部固定社交媒体区域的问题

要实现侧边栏底部固定社交区域,核心是利用Flex垂直布局让导航内容占据上方空间,将社交区域自动推至底部,同时确保滚动区域的高度设置正确。以下是具体修改步骤:

1. 修改侧边栏组件(HomeSidebar)

将组件最外层改为flex垂直容器,给导航区添加flex-grow-1让其占据剩余空间,社交区自然会被推到底部:

<template>
  <!-- 外层改为flex垂直布局,铺满高度 -->
  <div class="column h-100">
    <div class="navigation-links q-pa-lg flex-grow-1">
      <q-list padding>
        <q-item clickable v-ripple class="q-pa-md q-ma-md menu-item">
          <q-item-section avatar>
            <q-icon name="fa-solid fa-house" style="font-size:1.25rem"/>
          </q-item-section>
          <q-item-section>
            HOME
          </q-item-section>
        </q-item>

        <q-item active clickable v-ripple class="q-pa-md q-ma-md menu-item active-menu-item">
          <q-item-section avatar>
            <q-icon name="fa-solid fa-shirt" style="font-size:1.25rem"/>
          </q-item-section>
          <q-item-section>
            SERVICES
          </q-item-section>
        </q-item>

        <q-item clickable v-ripple class="q-pa-md q-ma-md menu-item">
          <q-item-section avatar>
            <q-icon name="fa-solid fa-envelope" style="font-size:1.25rem"/>
          </q-item-section>
          <q-item-section>
            CONTACT US
          </q-item-section>
        </q-item>
      </q-list>
    </div>
    <!-- 简化社交区域类名,保留基础样式 -->
    <div class="socialmedia-links q-pa-lg text-center">
      <div class="row justify-center">
        <q-btn flat size="sm" color="primary" round icon="fa-brands fa-google" aria-label="google" class="q-ma-sm no-shadow"/>
        <q-btn flat size="sm" color="primary" round icon="fa-brands fa-facebook-f" aria-label="facebook" class="q-ma-sm no-shadow"/>
        <q-btn flat size="sm" color="primary" round icon="fa-brands fa-instagram" aria-label="instagram" class="q-ma-sm no-shadow"/>
      </div>
      <h2 class="text-h5 text-weight-bolder q-mb-xs">CONNECT WITH US</h2>
      <h6 class="text-subtitle1 text-accent text-weight-normal q-my-none">If you like what you have seen so far we can guarentee you will appreciate our print quality.</h6>
    </div>
  </div>
</template>

<script setup>
  import { ref } from 'vue'

  const searchText = ref('')
</script>
<style lang="scss" scoped>
  .block-wrapper{
    max-width: 1024px;
    margin-left: auto;
    margin-right: auto;
  }

  .active-menu-item{
    background-color: $background-accent;
  }

  .menu-item{
    letter-spacing: .15rem;
    font-weight:500;
    border-radius: 7px;
  }
</style>

2. 修改布局组件中的抽屉容器

确保滚动区域内部的容器高度正确,让侧边栏组件能充分利用垂直空间:

<q-drawer
  v-model="navigationDrawer"
  bordered
  side="left"
  behavior="mobile"
  :width="$q.screen.width >= 400  ? 400 : $q.screen.width"
>
  <q-scroll-area class="fit">
    <!-- 改为flex垂直布局,铺满高度,内边距统一设置 -->
    <div class="column h-100 q-pa-lg">
      <div class="row justify-end">
        <q-btn flat round icon="fa-solid fa-xmark" aria-label="Menu" @click="toggleNavigationDrawer"/>
      </div>
      <!-- 让侧边栏组件占据剩余空间 -->
      <div class="flex-grow-1">
        <HomeSidebar/>
      </div>
    </div>
  </q-scroll-area>
</q-drawer>

关键修改点说明

  • 外层容器使用column h-100设置垂直flex布局并铺满高度
  • 导航区域添加flex-grow-1,使其占据除社交区外的所有垂直空间,自动将社交区推至底部
  • 滚动区域内部容器改为flex布局,确保子元素能正确分配垂直空间
  • 移除社交区多余的布局类,避免干扰默认flex逻辑

内容的提问来源于stack exchange,提问作者Qiuzman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 02:06:06