Troubleshooting Vertical Centering Issue with Flex in Ionic and ReactJS Not Yielding Results

Feel free to experiment with this Ionic / ReactJS project on Stackblitz:

https://stackblitz.com/edit/ionic-react-routing-ctdywr?file=src%2Fpages%2FGreetings.tsx

Here is the code snippet:

import React from 'react';
import { IonButton, IonContent, IonPage } from '@ionic/react';

const Greetings = () => {
  return (
    <IonPage className="loginPage">
      <IonContent fullscreen>
        <div
          className="container"
          style={{
            display: 'flex',
            flexDirection: 'column',
            justifyContent: 'center',
            alignItems: 'center',
          }}
        >
          <IonButton>Say Hello</IonButton>
          <IonButton>Say World</IonButton>
        </div>
      </IonContent>
    </IonPage>
  );
};

export default Greetings;

This code generates the following DOM content and CSS:

https://i.sstatic.net/VXXcj.png

The issue I'm facing: The buttons are supposed to be vertically and horizontally aligned but they appear differently as shown in the image below:

https://i.sstatic.net/1O3CQ.png

As you can see, the buttons are aligned at the top instead. Any suggestions on how to fix this?

Thank you!

Answer №1

This question was asked well and has a straightforward answer.

In this fork, IonRow and height 100% are missing.

<IonPage className="loginPage">
      <IonContent fullscreen>
        <IonRow
          className="container"
          style={{
            height: '100%',
            display: 'flex',
            flexDirection: 'column',
            justifyContent: 'center',
            alignItems: 'center',
          }}
        >
          <IonButton>Say Hello</IonButton>
          <IonButton>Say World</IonButton>
        </IonRow>
      </IonContent>
    </IonPage>

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 could be causing the issue of todo items not displaying correctly in the specified React component? (Using ASP.NET Core 2.0 with ReactJS and TypeScript)

Hello everyone, I am seeking some assistance and guidance on a React/Typescript issue I am facing with my new demo app. As a beginner in React/Typescript, I am using Visual Studio 2017 Community with asp.net core 2.0 and the react boiler project template. ...

having trouble installing ReactJS on MacOS

I am facing an issue with setting up ReactJS on my Mac. I am using npm version 4.1.2 and node version v7.7.4. After cloning the project from Git, I navigate to the project folder and try to run 'npm install' followed by 'npm start'. How ...

Dynamic row addition in Material Design Lite table causes format to break

Here's the HTML markup for creating a checkbox using material-design-lite: <label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="checkbox"> <input type="checkbox" id="checkbox" class="mdl-checkbox__input" /> <span c ...

Real-time collaborative Whiteboard using WebSocket technology (socket.io)

I am currently working on developing a collaborative online whiteboard application using HTML5 canvas, Node.js, and Websockets (Socket.io). While my progress is going well, I am facing some challenges when it comes to drawing circles. I have been successfu ...

Dynamic Entry: The Art of JQuery Animation

I want to achieve a sequential flying-in effect when my page loads, with each div sliding in one by one. Currently, all the divs fly in simultaneously, but I'd like them to come in sequentially. Here is my code snippet: <script> function ani ...

Populate the content of the child DIV to match the grid layout as a whole

I am attempting to control the layout of the grid on my website using CSS. By utilizing Bootstrap 4, I have created two divs with equal height using display:grid. However, I am facing difficulties in managing the child elements within these divs. I am tryi ...

Centralize and confine the menu division

I have been working on creating a hover menu using CSS and Bootstrap, specifically for flex grid layouts. However, I have run into an issue where my menu is only as wide as its parent div. Furthermore, I am struggling to center the hover menu relative to ...

nyroModal automatically adapts its dimensions according to the size of the webpage, not the size of

A situation has arisen with a link that opens an image using nyroModal. While everything is functioning correctly, the Modal window appears in the center of the page instead of aligning with the middle of the browser window. As a result, only the upper por ...

When trying to fetch data from a React front end using axios, the request body's title is coming back

I am facing an issue where I keep receiving 'undefined' when attempting to console.log(req.body.title). Additionally, when I console.log(req.body), I am only seeing an empty {} returned. My setup involves React for the frontend and express for t ...

Picture hidden beyond the words

I am trying to achieve a layout where an image is displayed behind an H1 tag, with the width of the image matching the width of the text. Here is my code: <div style="display: inline;"> <img src="http://img585.imageshack.us/img585/3989/m744. ...

registering a back button action in Ionic2 for multiple pages

Currently, I am in the process of developing my Ionic2 app and have encountered a dilemma regarding the functionality of registerBackButtonAction. On one page, let's call it pageA, I have implemented this function and everything is functioning as exp ...

Encountered an issue retrieving information from the API - connection to the server could not be established - encountered an 'Access-Control-Allow-Origin' error

I'm having trouble submitting a form and receiving the data via email. When I try, it shows an error message: http://localhost:4000/contact net::ERR_CONNECTION_REFUSED I've attempted to resolve this issue by trying different cors options. Here a ...

Instead of being arranged vertically, the tables are positioned horizontally on display

I am attempting to generate a table using PHP and HTML that pulls data from a MySQL database. The issue I'm facing is that the data is appearing horizontally rather than vertically. if (isset($_POST['winneron'])) { echo "<tr>"; ...

Steps to center an HTML canvas on the screen

I attempted to center my canvas horizontally using <div style="text-align:center;">, but the y axis remains unchanged. How can I position the HTML canvas in the center of both the x and y axes? Any suggestions on how to achieve this alignm ...

Sending data from HTML and JavaScript to Python

In the process of developing a website that will operate on an embedded device, I am implementing an interface for users to engage with multiple functions on the site. These functions within the HTML interface will communicate with a Python script, which i ...

The correct terminology for divs, spans, paragraphs, images, anchor tags, table rows, table data, unordered lists, list

Just wondering, I've noticed that every time I come across a page element '<###>[content]<###>' and want to learn how to manipulate it, I usually search for something like "how to do x with div" or "how to get y from div". I know ...

Mobile Image Gallery by Adobe Edge

My current project involves using Adobe Edge Animate for the majority of my website, but I am looking to create a mobile version as well. In order to achieve this, I need to transition from onClick events to onTouch events. However, I am struggling to find ...

Automating button clicks after a component has loaded in Angular 2+ can be achieved by implementing a

Currently, I am working on implementing an automatic search function in Angular that triggers after a component loads. Right now, the function is triggered by a button click, but I want to automate this process. <button mat-raised-button class="mat-whi ...

inherited background colors are not passed down

I am having issues with applying the background and padding in my CSS. It seems that my CSS is not overriding the Bootstrap styles, and when I apply the container style, the display property is not working as expected. Here is the code snippet: ...

Utilizing Google Maps API version 3 to display various groups of markers

I am encountering an issue while trying to plot fixed markers and a user position marker on a Google Map. I want to use different images for these markers, but something strange is happening. When the page loads, all fixed markers show up correctly initial ...