What is the best way to align the logo image in the center of the header vertically?

I am trying to vertically center my logo, but I have not been successful with using margin: auto or margin: center.

Here is what I have tried so far: ・text-align: center; ・margin: auto; ・margin: center: ・navbar-brand-center

The logo currently appears on the top left corner. When the user clicks on the logo image, it should take them to home.vue (route /).

My current workaround involves using margin:-1.8% 0%, but I understand that this is not an elegant solution.

If you have any suggestions, please advise me.

<b-navbar-brand :to="`/${$i18n.locale}/`">
         <img :src="image" class="logo"/>
     </b-navbar-brand>
.logo{
   width: 50px;
   position:absolute;
   height: 50px;
   margin:-1.8% 0%;  
}

I would like to change from ↓https://i.stack.imgur.com/cNp0d.png

To this ↓ https://i.stack.imgur.com/XNfbP.png

Full code below

<template>
  ...
</template>

<script>
import image from "../assets/Logo.jpg"
export default {
  name: "Header",
  data() {
    return {
      image: image
    };
  },
  methods: {
    ...
  },
  computed: {
  ...
  }
};
</script>

<style>
#header {
  background-color: cornflowerblue;
}
.logo{
   width: 50px;
   position:absolute;
   height: 50px;
   margin:-1.8% 0%;  
}

@media screen and (max-width: 891px) {
  .center {
    position: relative !important;
}

}

.center {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}
</style>

Answer №1

Utilizing flexbox is a great option here. By setting align items center, you can easily vertically align items in the center.

#header{ 
    display : flex;
    align-items:center;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to create an answer label box that validates your response?

I am looking to design a question box label that resembles a search box. In this unique setup, users will have the option to input their answer into the question label. For example, if the user types 'kfuffle' as the answer, they will automatical ...

Using VueJs and Laravel 5 for On input implementation

After following the steps outlined in the mentioned tutorial, I was able to achieve a perfect validation setup. However, my goal now is to implement real-time form validation without relying on a traditional submit button. I want the validation to occur as ...

Restrict access to API routes to only users who have been properly authenticated

Seeking assistance with restricting access to certain API routes only to authenticated users using Laravel's default authentication system. Following successful login, encountering an "Unauthenticated" message when attempting to access a specific rout ...

tips for scrolling divs horizontally within the main container

I've been attempting to scroll horizontally, but even though the scroll bar is visible, it's not functioning. Here's the code: <!DOCTYPE html> <html> <head> <title>qwe</title> </head> <body> < ...

Setting up PostCSS nesting with Vite: A beginner's guide

Here are the steps I have taken so far: I installed postcss-nesting using npm install postcss-nesting --save-dev I configured vite.config.js as follows: import { fileURLToPath, URL } from 'url'; import { defineConfig } from 'vite&apo ...

Transitioning from Vue2 to Vue3

I have been working on migrating from Vue2 to Vue3. I updated most of the packages to their latest versions and removed some redundant ones to streamline the process. Here is an overview of my package.json: { "private": true, "script ...

Guide on creating 2 select inputs with distinct elements?

Imagine you have two select inputs called 'Favorite Fruits' and 'Least Favorite Fruits'. Both of them contain a list of 5 fruits. // The following code is an example to demonstrate the issue <select name='favoriteFruits'& ...

Why Isn't This JPG Image Functioning Properly in HTML/CSS?

I am facing an issue with a JPG image that I am attempting to use in CSS as a background-image for a div container. For some reason, this particular image refuses to render in the viewport. Interestingly, when I inspect the element, I can see its thumbnail ...

Having issues with Vue Devtools functionality on my local environment

Despite working perfectly on all online demos and examples, I am facing an issue with Vue Devtools not functioning on my local pages. Even after implementing the code snippet below, the Vue Devtools icon stays gray and displays the message "Vue.js not de ...

What are the steps to enable CSS code completion for JavaFX again?

Hello everyone, Recently, I disabled the CSS code completion feature for JavaFX-Tags such as '-fx-...'. Unfortunately, I'm not sure how or why it happened but now I would like to enable the code suggestions again. I have been unable to loca ...

How can I effectively vertically position a button in Bootstrap 5 without compromising its functionality?

I'm attempting to reposition the sign-up buttons for Google, Apple, and email below where it says "join," but they stubbornly refuse to budge even when I try to force them with CSS. https://i.sstatic.net/74LQk.jpgCSS .homepage_topRight_Buttons{ ...

Retrieve the current font style with Kendo UI Editor

Recently, I've been facing some challenges while working with the Kendo UI Editor. Specifically, I'm struggling to retrieve the current font style. My goal is to use JavaScript or jQuery to obtain the following values: Values I am looking for: ...

What is preventing Kohana from reading my CSS?

Recently, I launched my website kipclip.com on the Kohana platform and added a new rental page. However, the CSS and JS files are not being applied to this page. I've looked into how these files are included in Kohana but haven't had any luck so ...

No visible changes from the CSS code

As I create a small HTML game for school, I'm facing an issue with styling using CSS. Despite my efforts to code while using a screen reader due to being blind, the styling of an element isn't being read out as expected. The content seems to be c ...

Vue Subroutes within nested components do not automatically load

My application features a sidebar that I want to utilize to load the Patient view by default when accessing patient/:id. This should also trigger the loading of the PatientDashboard sub-view. Within the Patient view component, there is a router-view that ...

fixed divs that remain in place while scrolling

In the past, I have implemented a method similar to this: However, I am not a fan of the "flicker" effect that occurs when the page is scrolled and the div needs to move along with it. Recently, I have come across websites where certain elements (such as ...

pointing out the existing issues with the menu

I am struggling to figure out why I cannot highlight the current menu page on a navigation bar (aside from the fact that I am a complete beginner :-) I have tried using a JQuery function that I found online, but none of them seem to work. Here is the funct ...

Utilizing Vue Store Methods within an Array or Object

Imagine we have 5 identical buttons. Instead of duplicating them, I decided to make use of v-for. methods: { a() {}, b() {}, ... } Replacing the individual buttons with: <v-btn block color="primary" class="my-1" @click="a">A</v-btn ...

Swap out the content in a text input box with the text chosen from a suggested autocomplete option

I am working on a text input box with auto-complete options displayed below it. I want to enable users to navigate through the options using keyboard arrows and "select" one, causing it to change color. How can I update the text in the input box with the s ...

The two CSS classes are styled with different border-color values, but only one is being applied correctly

My goal is to modify the border color of a textarea using jQuery. Previously, I achieved this by using .css("border-color","rgb(250,0,0)"), and it was working perfectly. However, I have now been advised against using CSS directly in JavaScript and told to ...