你可以如何将 logo 居中在 Vuetify 应用栏内?

huangapple go评论58阅读模式
英文:

How can i center the logo inside vuetify app bar?

问题

我需要内部的标志确切地显示在应用栏中间。如何在考虑应用栏内的其他元素的情况下实现这个效果?

我尝试在v-app-bar-icon之后使用v-spacer,但结果并不感觉居中。

我试图实现的一个示例是官方的 nuxt 站点应用栏(当显示在中等尺寸以下时):https://nuxtjs.org/

<v-app-bar fixed app>
  <v-app-bar-nav-icon
    aria-label="显示或隐藏导航菜单"
    @click.stop="drawer = !drawer"
  ></v-app-bar-nav-icon>
  <nuxt-link aria-label="主页" to="/">
    <v-img
      v-show="searchClosed"
      :src="require('~/assets/images/example_Logo.svg')"
      max-height="55px"
      max-width="110px"
      class="mb-1"
      contain
    ></v-img>
  </nuxt-link>
  <v-spacer v-show="searchClosed"></v-spacer>
  <v-btn v-show="searchClosed" aria-label="显示用户菜单" icon>
    <v-icon>mdi-account-circle</v-icon>
  </v-btn>

  <transition name="slide-fade">
    <nav-search
      v-show="!searchClosed"
      @search-opened="searchClosed = false"
      @search-closed="searchClosed = true"
    ></nav-search>
  </transition>

  <v-btn
    v-show="searchClosed"
    aria-label="显示或隐藏搜索输入"
    icon
    @click="searchClosed = false"
  >
    <v-icon>mdi-magnify</v-icon>
  </v-btn>
</v-app-bar>
英文:

I need the logo inside to be displayed exactly in the middle of the app bar. How can I achieve this result taking into consideration the other elements inside the app bar?

I tried using v-spacer after the v-app-bar-icon, but the result doesn't feel centered at all.

One example of what I am trying to achieve is the official nuxt site app bar (when the display is below md size): https://nuxtjs.org/

&lt;v-app-bar fixed app&gt;
      &lt;v-app-bar-nav-icon
        aria-label=&quot;show-or-hide-navigation-menu&quot;
        @click.stop=&quot;drawer = !drawer&quot;
      /&gt;
      &lt;nuxt-link aria-label=&quot;home-page&quot; to=&quot;/&quot;&gt;
        &lt;v-img
          v-show=&quot;searchClosed&quot;
          :src=&quot;require(&#39;~/assets/images/example_Logo.svg&#39;)&quot;
          max-height=&quot;55px&quot;
          max-width=&quot;110px&quot;
          class=&quot;mb-1&quot;
          contain
        &gt;&lt;/v-img&gt;
      &lt;/nuxt-link&gt;
      &lt;v-spacer v-show=&quot;searchClosed&quot;&gt;&lt;/v-spacer&gt;
      &lt;v-btn v-show=&quot;searchClosed&quot; aria-label=&quot;show-user-menu&quot; icon&gt;
        &lt;v-icon&gt;mdi-account-circle&lt;/v-icon&gt;
      &lt;/v-btn&gt;

      &lt;transition name=&quot;slide-fade&quot;&gt;
        &lt;nav-search
          v-show=&quot;!searchClosed&quot;
          @search-opened=&quot;searchClosed = false&quot;
          @search-closed=&quot;searchClosed = true&quot;
        &gt;&lt;/nav-search&gt;
      &lt;/transition&gt;

      &lt;v-btn
        v-show=&quot;searchClosed&quot;
        aria-label=&quot;show-or-hide-search-input&quot;
        icon
        @click=&quot;searchClosed = false&quot;
      &gt;
        &lt;v-icon&gt;mdi-magnify&lt;/v-icon&gt;
      &lt;/v-btn&gt;
    &lt;/v-app-bar&gt;

答案1

得分: 1

  1. 尝试在标志图像前后放置 v-spacer -
&lt;v-app-bar
  color="deep-purple accent-4"
  dense
  dark
&gt;
  &lt;v-app-bar-nav-icon&gt;&lt;/v-app-bar-nav-icon&gt;
  &lt;v-spacer&gt;&lt;/v-spacer&gt;
  &lt;v-img
    src="https://picsum.photos/200/300"
    max-height="55px"
    max-width="110px"
    class="mb-1"
    contain
    &gt;&lt;/v-img&gt;
  &lt;v-spacer&gt;&lt;/v-spacer&gt;
  &lt;v-btn icon&gt;
    &lt;v-icon&gt;mdi-heart&lt;/v-icon&gt;
  &lt;/v-btn&gt;
  &lt;v-btn icon&gt;
    &lt;v-icon&gt;mdi-magnify&lt;/v-icon&gt;
  &lt;/v-btn&gt;
&lt;/v-app-bar&gt;
  1. 使用网格系统 -
&lt;v-app-bar
  color="deep-purple accent-4"
  dense
  dark
&gt;
  &lt;v-row&gt;
    &lt;v-col align="start"&gt;
      &lt;v-app-bar-nav-icon&gt;&lt;/v-app-bar-nav-icon&gt;
    &lt;/v-col&gt;
    &lt;v-col align="center"&gt;
      &lt;v-img
        src="https://picsum.photos/200/300"
        max-height="55px"
        max-width="110px"
        class="mb-1"
        contain
        &gt;&lt;/v-img&gt;
    &lt;/v-col&gt;
    &lt;v-col align="end"&gt;
      &lt;v-btn icon&gt;
        &lt;v-icon&gt;mdi-heart&lt;/v-icon&gt;
      &lt;/v-btn&gt;
      &lt;v-btn icon&gt;
        &lt;v-icon&gt;mdi-magnify&lt;/v-icon&gt;
      &lt;/v-btn&gt;
    &lt;/v-col&gt;
  &lt;/v-row&gt;
&lt;/v-app-bar&gt;

(请注意,我已经将尖括号 <> 替换为 &lt;&gt;,以便在文本中正确显示 HTML 代码。)

英文:

There are two ways to do this-

1. Try putting the v-spacer before and after the logo image-

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-js -->

new Vue({
  el: &#39;#app&#39;,
  vuetify: new Vuetify(),
  
})

<!-- language: lang-html -->

&lt;script src=&quot;https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.js&quot;&gt;&lt;/script&gt;
&lt;link href=&quot;https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css&quot; rel=&quot;stylesheet&quot;&gt;
&lt;link href=&quot;https://cdn.jsdelivr.net/npm/@mdi/font@6.x/css/materialdesignicons.min.css&quot; rel=&quot;stylesheet&quot;&gt;
&lt;div id=&quot;app&quot;&gt;
  &lt;v-app id=&quot;inspire&quot;&gt;
    &lt;div&gt;
      &lt;v-app-bar
        color=&quot;deep-purple accent-4&quot;
        dense
        dark
        &gt;
        &lt;v-app-bar-nav-icon&gt;&lt;/v-app-bar-nav-icon&gt;
        &lt;v-spacer&gt;&lt;/v-spacer&gt;
        &lt;v-img
          src=&quot;https://picsum.photos/200/300&quot;
          max-height=&quot;55px&quot;
          max-width=&quot;110px&quot;
          class=&quot;mb-1&quot;
          contain
          &gt;&lt;/v-img&gt;
        &lt;v-spacer&gt;&lt;/v-spacer&gt;
        &lt;v-btn icon&gt;
          &lt;v-icon&gt;mdi-heart&lt;/v-icon&gt;
        &lt;/v-btn&gt;
        &lt;v-btn icon&gt;
          &lt;v-icon&gt;mdi-magnify&lt;/v-icon&gt;
        &lt;/v-btn&gt;
      &lt;/v-app-bar&gt;
    &lt;/div&gt;
  &lt;/v-app&gt;
&lt;/div&gt;

<!-- end snippet -->

2. Use the grid system-

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-js -->

new Vue({
  el: &#39;#app&#39;,
  vuetify: new Vuetify(),
  
})

<!-- language: lang-html -->

&lt;script src=&quot;https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.js&quot;&gt;&lt;/script&gt;
&lt;link href=&quot;https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css&quot; rel=&quot;stylesheet&quot;&gt;
&lt;link href=&quot;https://cdn.jsdelivr.net/npm/@mdi/font@6.x/css/materialdesignicons.min.css&quot; rel=&quot;stylesheet&quot;&gt;
&lt;div id=&quot;app&quot;&gt;
  &lt;v-app id=&quot;inspire&quot;&gt;
    &lt;div&gt;
      &lt;v-app-bar
        color=&quot;deep-purple accent-4&quot;
        dense
        dark
        &gt;
        &lt;v-row&gt;
          &lt;v-col align=&quot;start&quot;&gt;
            &lt;v-app-bar-nav-icon&gt;&lt;/v-app-bar-nav-icon&gt;
          &lt;/v-col&gt;
          &lt;v-col align=&quot;center&quot;&gt;
            &lt;v-img
              src=&quot;https://picsum.photos/200/300&quot;
              max-height=&quot;55px&quot;
              max-width=&quot;110px&quot;
              class=&quot;mb-1&quot;
              contain
              &gt;&lt;/v-img&gt;
          &lt;/v-col&gt;
          &lt;v-col align=&quot;end&quot;&gt;
            &lt;v-btn icon&gt;
              &lt;v-icon&gt;mdi-heart&lt;/v-icon&gt;
            &lt;/v-btn&gt;
            &lt;v-btn icon&gt;
              &lt;v-icon&gt;mdi-magnify&lt;/v-icon&gt;
            &lt;/v-btn&gt;
          &lt;/v-col&gt;
        &lt;/v-row&gt;
      &lt;/v-app-bar&gt;
    &lt;/div&gt;
  &lt;/v-app&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年2月16日 03:24:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75464571.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定