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 advantages do front-end framework wrappers offer for charting libraries such as vue-chartjs, react-chartjs-2, and others?

What advantages come with utilizing a front-end framework wrapper for Javascript charting libraries? One significant advantage I have discovered is the ability to import only specific charts that are needed (such as importing { Bar }...), as opposed to us ...

Layout your Angular components with a column design using Flex Layout

Is there a way to adjust the width of a child component in an fxLayout set to column? Take this example for reference: https://stackblitz.com/edit/angular-fxlayout-custom-breakpoints?file=app%2Ftest.component.ts In the provided example, there are three f ...

Using Vue.js to process JSON data

My issue lies within this JSON data. I am trying to consume only the first element of the array using Vue.js 2 in order to display it. I was able to achieve this successfully using the console, but not with Vue.js. This line of code in the console works: ...

Using static props to transmit API call information

I am developing a Vue.js application that requires multiple API calls. I am utilizing the tmdb API to incorporate sections for popular, upcoming, and top-rated movies in my app. All of these sections use the same API call, which is shown below (for popular ...

Set up specific vue.config.js configurations for unique environments in Vue

I am working on a multi-page app where I want certain pages to only show up in my development environment. Here's how my vue.config.js looks: module.exports = { productionSourceMap: false, pages: { index: "src/main.js", admin: { ...

Tips for connecting Vue data to a dropdown menu

While diving into Vue.js, I'm encountering a puzzling issue. Despite receiving data from the server (5 records), it's not populating the <select> element properly. Instead of multiple options, all I see is a single one displaying {{dept.DNa ...

How can I align an input to the right using Bootstrap?

I found an example of a navbar that I liked and decided to copy it. Here is the code snippet: <div class="container"> <h3>Nawigacja zamknieta w kontenerze</h3> <nav class="navbar navbar-toggleable-md navbar-light bg-faded"> < ...

Error: Cannot access properties that are undefined (specifically '$store')

Login With Vue.js <template> <div class="container mt-5"> <div class="row"> <div class="col-md-12"> <div class="col-md-6"> <div class="form-group&qu ...

Is there a way to have a fixed width div positioned in the center of the screen, with two additional divs on either side

I have come across this stunning image: https://i.stack.imgur.com/tUYMc.png It serves as a header for a website - click on it to see the full size. I am trying to replicate this using HTML, CSS, and images, but I'm struggling. It needs to be 100% w ...

Is it possible to include aria-controls in an anchor tag?

My primary navigation includes some elements that may have a secondary navigation. In order to optimize accessibility on my website, I am seeking the most effective way to show/hide the secondary nav. After brainstorming, here is what I have come up with: ...

What is the method to establish the table format in HTML using several for each loops?

I need to arrange the table structure for product plans as follows: +------------------+---------------+---------------+ | product1 | product2 | product3 | +------------------+---------------+---------------+ | product1plan1 | product ...

What is the best way to troubleshoot a quasar typescript file type error?

Currently, I am delving into Quasar using TypeScript and encountering a type error while working on file uploads. Here is the snippet of my code where the type error arises specifically in the parameter of the form.append() method. The error message read ...

Ways of accessing an array within an if statement

I have a dashboard with admin privileges for my application. In this dashboard, the admin can select a user from a dropdown list. Once a user is selected, I make an AJAX call to retrieve the user's data and store it in a variable named $result. Howeve ...

Nesting maps in JavaScript is a powerful way to transform

I'm in the process of developing a budgeting app using React and JavaScript. At the moment, I have successfully generated a table displaying various costs. Name Budget Used $ Used % Available Food 300 300 100 0 Streaming services 600 600 100 ...

Restrict the number of dynamic form elements to a maximum of 10 entries

I am working on a feature where users can refer their friends and the data will be saved in a database. <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <script type='text/javascript' sr ...

Steps to showcase specific data in the bootstrap multi-select dropdown menu sourced from the database

Utilizing CodeIgniter, I have set up multiple select dropdowns using bootstrap. The issue I am facing is with displaying the selected values in these drop-downs on the edit page. Would appreciate some guidance on how to tackle this problem. Here is a sni ...

Is there any HTML code that is able to implement a currency format identical to the one we've customized in Google Sheets/Google Apps Script

I am currently working with a Google Sheet table that consists of 2 columns. The second column contains charges which can vary based on user input through a Google Form and are summed up using GAS. To view an example, click here. The data from this Googl ...

I am curious about the Vue component architecture and have some inquiries regarding its structure

While teaching myself Vue, I encountered a problem. Initially, I connected some components using new Vue ({el:" # id "}). However, when I linked the root component <div id = "app"> with new Vue ({el:" # app "}), it disrupted the existing bindings. ...

Using the jquery slider in conjunction with the onchange event

I have integrated a jquery slider add-on into my project that updates a value in a Linux file whenever it is manipulated. The slider is connected to a text input box, which is set as readonly and therefore always blurred. The issue I am facing is that the ...

Hover over the image to reveal sliding text

I am attempting to incorporate a CSS3 hover effect into my images, where hovering over an image will cause some text to slide up on a white background. However, I have encountered issues with conflicting code, as I also have overlay text and a 'new&ap ...