【问题标题】:How to put a background image behind the nav bar?如何在导航栏后面放置背景图片?
【发布时间】:2021-06-23 05:35:17
【问题描述】:

我是 Nuxt Js 的新手,无法将背景放在导航栏后面。

Nav.vue

<style scoped>
.padding {
    padding: 5px;
    background-color: #082F4D
}
.navbar {
    position: absolute;
    overflow: hidden;
}
.navbar a {
    float: left;
}
</style>

index.vue

<div class="container">
  <FirstPageFirstSection />
</div>

...
<style>
.container {
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
}
</style>

FirstPageFirstSection.vue

<style scoped>
.Hero {
  background-image: url("~/assets/logo/xx.jpeg");
  min-height:300px;
    /* Center and scale the image nicely */
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  position: relative;
  display: flex;
  align-items: flex-start;
}
</style>

【问题讨论】:

    标签: nuxt.js


    【解决方案1】:

    如果您想要动态背景图片,则需要在模板中执行此操作(据我所知,可能在 Vue3 的 style 部分中可行,但在 Vue2 中不可行)。

    这个答案可能会有所帮助:https://stackoverflow.com/a/66365980/8816585

    差不多就是这个

    <div :style="{ backgroundImage: `url(${require('~/assets/logo/xx.jpeg')})`}"></div>
    

    【讨论】:

    • 我不确定这是否是必需的。但是我通过在添加导航栏容器之前先放置背景容器成功添加了背景。
    • 我不知道你的观点是什么样的,所以我不能说。我在这里指的是 Vue 问题,而不是 CSS 问题。但是,是的,您当然不需要将其隐藏在某些东西下面。希望我的回答能帮助@user16295310
    猜你喜欢
    • 1970-01-01
    • 2012-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多