Strategies for aligning the "Avatar" Material UI component in the center of a div when utilizing ReactJS and Material UI

Having trouble centering an avatar material UI component in my project. I've tried various methods such as text-align, justify-content, margin: auto but nothing seems to be working. Any assistance would be greatly appreciated.

/////profile.js///////

<div className="myProfile__outterContainer">
      <div className="myProfile__innerContainer">
        <div className="myProfile__header">
          <h2>My Profile</h2>
          <Avatar
            alt={user.displayName}
            src={user.photoURL}
            className={classes.large}
          />
          <h2>Welcome, {user.displayName}</h2>
        </div>
      </div>
    </div>

 
////// profile .css below
profile.css

    .myProfile__outerContainer {
  display: flex;
  justify-content: center;
  margin-top: 5vh;
}

.myProfile__innerContainer {
  position: relative;
  width: 800px;
  padding: 20px;
  max-width: 85vw;
  height: 75vh;
  border-radius: 20px;
  background-size: cover;
  background-position: center;
  box-shadow: 0px 18px 53px 0px rgba(0, 0, 0, 0.3);
}
.myProfile__header {
  text-align: center;
  justify-content: center;
  
}

Answer №1

To align both <h2> tags and the Avatar vertically in the center:

.myProfile__header {
  display : flex;
  flex-direction : column;
  align-items : center;
  justify-content : 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

Various methods for communicating between nested directives

There are numerous methods for communication between directives. For instance, in the case of nested directives where inner directives need to communicate something to the outer directive (e.g., user selection). <outer> <inner></inner> ...

Continuously refreshing local storage with the latest updates

Can you please help me understand why each time I add an item to local storage, it gets updated instead of creating a new one? It seems like my code is not generating unique IDs, but I'm struggling to figure out how to resolve this issue... Here is t ...

What steps can be taken to troubleshoot issues with the jquery mask plugin?

I am using the jQuery Mask Plugin available at to apply masks to input fields on my website. Currently, I am trying to implement a mask that starts with +38 (0XX) XXX-XX-XX. However, I am facing an issue where instead of mandating a zero in some places, ...

Guide to importing a scss file into a scss class

Is there a way to apply a different theme by adding the "dark-theme" class to the body? I've attempted the following implementation: @import '../../../../node_modules/angular-grids/styles/material.scss'; .app-dark { @import '../../. ...

Ways to extract information from complex JSON structures with more than 5 nested layers

I'm currently using a Teleport API to fetch data. The JSON structure of the data is quite complex with multiple nested levels, making it challenging for me to extract the necessary information. Here's a snippet of the data I'm dealing with. ...

Why does Next.js throw an error when using an additional <div></div>?

I'm new to exploring Next.js and I'm encountering an error when using the html tag twice. It works fine with just one container, but as soon as I add another one, this error pops up: Error: error: Unexpected token "div". Expected jsx i ...

Displaying every nth image in a new row of a CSS grid

I have a react component and I want to arrange 3 photos inline in a row with their names below each photo, and then continue in new rows for the next set of 3 elements and so on... I attempted to use :nth-child(3n+1) but encountered some issues... const P ...

Optimal location for executing Js to render a partial within the Rails framework

I had a plan to update a partial using a click event where data was fetched via ajax. I navigated to my assets/javascripts directory and placed the code in the js file of the module I intended to call it on. I successfully fetched the data and performed so ...

Alias destructuring for arrays within nested objects

I'm currently attempting to change the names of certain objects from one array (eventFetch) and transfer them into another array (mapEvents). I initially tried using destructuring aliases for this task, but since I need to rename a nested object, it d ...

The unit tests are not triggering the execution of setTimeout

Currently, I am developing a project in TypeScript and for unit-tests, I am utilizing QUnit and sinonjs. One of the functions within my code dynamically renders UI elements. I need to retrieve the width of these dynamic elements in order to perform additio ...

Scroll feature not functioning correctly on Chrome and Opera browsers

In my testing, I have found that the scrollto function does not work in Chrome and Opera. However, it works fine in Firefox. I am unsure of what the issue could be. Any help would be greatly appreciated. function scroll_to_word(){ var pos = $('.cont ...

Create a ReactJs hierarchical tree component that illustrates the relationship between employees and managers

I need to create a ReactJs Tree component using Material UI that displays managers and their employees. When a manager is clicked, the component should expand to show all employees reporting to them. How can I achieve this with the provided data structure? ...

Adding a conditional statement to a directive depending on the existence of an attribute - a step-by-step guide!

Here is the code snippet that I have been working on: HTML Code: <update-field name="test" cap></update-field> JS Code: scope: { name: "@", cap: "@" }, controller: function() { }, link: function(scope, elem, attr, ct ...

What is the best way to limit the top margin for a fixed element?

Recently, I came across this code snippet: jQuery(document).ready(function($){ $( window ).scroll(function() { var current_top = $(document).scrollTop(); var heights = window.innerHeight; document.getElementById("sHome").styl ...

Achieving precise alignment of div content through Css techniques

body { margin: 0; font-family: Arial, Helvetica, sans-serif; } .topnav { overflow: hidden; background-color: #333; } .topnav a { float: left; display: block; color: #f2f2f2; text-align: center; padding: 14px 16px; text-decoration: ...

Displaying time and user names on Discord Rich Presence

I am currently developing a Discord bot in JavaScript that responds with "User has been playing GameName for Hours" when a specific command is called. My code functions properly when the mentioned user is playing a game without rich presence support. Howev ...

How can I update a Django webpage using AJAX without having to refresh it?

I'm currently in the process of developing a messaging application and I'd like to implement a feature that automatically reloads the page every minute so users can see new messages without having to manually refresh. While I have some knowledge ...

Tips for achieving vertically centralized components with uniform height columns in Bootstrap 4

I tried implementing the solution provided in this question: Bootstrap 4 vertical center - equal height cards However, I am still facing an issue. Despite applying the suggested code: <div class="cycle-des h-100 justify-content-center">Product Cycl ...

Looking to add tiered custom attribute select boxes in SnipCart - how can I make it happen?

I am interested in implementing two custom attributes for products, where the options for the second custom attribute are determined by the selection of the first attribute. My specific situation involves selling art in various formats and sizes, with dif ...

When utilizing a JQuery plugin for sliders, Dart does not function in the same way that traditional JavaScript does

Starting out with Dart for Front-End development has been a bit challenging for me. I am trying to incorporate a JQuery plugin called FlexSlider using the Js-Interop Dart Library. However, it's not functioning as expected compared to pure JavaScript, ...